archive
/
tstatic
Archived
1
Fork 0

make server more like normal servers

This commit is contained in:
Jake Howard 2016-05-16 13:07:18 +01:00
parent 183ed097f2
commit be54cb9083
1 changed files with 17 additions and 1 deletions

View File

@ -1,7 +1,10 @@
const express = require('express');
const PORT = process.env.PORT;
const serveDir = __dirname + '/site/';
const serveDir = __dirname + '/site';
const directory = /\/$/;
const allFiles = /.*/;
const expressConfig = {
dotfiles: 'deny',
@ -11,10 +14,23 @@ const expressConfig = {
const app = express();
app.use(function (request, response, next) {
// If path is directory then serve index.html
if (directory.exec(request.url)) {
request.url += '/index.html';
}
next();
});
app.use(
express.static(serveDir, expressConfig)
);
// Cannot find any file
app.use(
allFiles, express.static(serveDir + '/core/404.html', expressConfig)
);
const server = app.listen(PORT, function () {
const serverPort = server.address().port;
console.log('Server started on port ' + serverPort);