1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
theorangeone.net-legacy/scripts/server.js

38 lines
757 B
JavaScript
Raw Normal View History

2016-08-06 20:31:04 +01:00
const express = require('express');
const PORT = process.env.PORT;
const serveDir = __dirname + '/../output';
const directory = /\/$/;
const allFiles = /.*/;
const expressConfig = {
dotfiles: 'deny',
index: false,
redirect: true
};
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 + '/.404.html', expressConfig)
);
const server = app.listen(PORT, function () {
const serverPort = server.address().port;
console.log('Server started on port ' + serverPort);
});