From be54cb908387f04a0c989e0b62bb78eac08cfecb Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 16 May 2016 13:07:18 +0100 Subject: [PATCH] make server more like normal servers --- server.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 978474e..a677e3e 100644 --- a/server.js +++ b/server.js @@ -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);