This repository has been archived by the owner on Jan 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (38 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var express = require("express");
var logfmt = require("logfmt");
var app = express();
var distFolder = __dirname + '/dist';
var port = process.env.PORT || 8080;
var env = process.env.ENV || "development";
if (env === "staging") {
var username = process.env.HTTP_USERNAME;
var password = process.env.HTTP_PASSWORD;
var requireAuthentication = express.basicAuth(function(user, pass) {
return (user == username && pass == password);
},'pebble {code} development area');
// Protect all pages with authentication
app.all('*', requireAuthentication);
}
app.use(logfmt.requestLogger());
app.use(express.static(distFolder));
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
app.engine('html', require('ejs').renderFile);
// Simple processing of pages
// Mainly to remove .html extension
app.get('/:page', function(req, res) {
var page = req.param('page');
if (page) {
var pageFile = page + '.html';
var path = distFolder + "/" + pageFile;
res.render(path);
} else {
throw "Can't find page: " + page;
}
});
var port = Number(port);
app.listen(port, function() {
console.log("Listening on " + port);
});