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.
tstatic/server.js

38 lines
756 B
JavaScript
Raw Normal View History

2016-05-16 08:37:24 +01:00
const express = require('express');
const PORT = process.env.PORT;
2016-05-16 13:07:18 +01:00
const serveDir = __dirname + '/site';
const directory = /\/$/;
const allFiles = /.*/;
2016-05-16 08:37:24 +01:00
const expressConfig = {
dotfiles: 'deny',
index: false,
redirect: true
};
const app = express();
2016-05-16 13:07:18 +01:00
app.use(function (request, response, next) {
// If path is directory then serve index.html
if (directory.exec(request.url)) {
request.url += '/index.html';
}
next();
});
2016-05-16 08:37:24 +01:00
app.use(
express.static(serveDir, expressConfig)
);
2016-05-16 13:07:18 +01:00
// Cannot find any file
app.use(
allFiles, express.static(serveDir + '/core/404.html', expressConfig)
);
2016-05-16 08:37:24 +01:00
const server = app.listen(PORT, function () {
const serverPort = server.address().port;
console.log('Server started on port ' + serverPort);
});