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);