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

37 lines
721 B
JavaScript

const express = require('express');
const PORT = process.env.PORT;
const serveDir = __dirname + '/site';
const directory = /\/$/;
const allFiles = /.*/;
const expressConfig = {
dotfiles: 'ignore',
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 () {
console.log('Server started on port ' + server.address().port);
});