make server more like normal servers
This commit is contained in:
parent
183ed097f2
commit
be54cb9083
1 changed files with 17 additions and 1 deletions
18
server.js
18
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);
|
||||
|
|
Reference in a new issue