-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpress.js
31 lines (25 loc) · 813 Bytes
/
express.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(function () {
const express = require('express');
const throng = require('throng');
const {join} = require('path');
const staticDir = 'src/assets/static';
const sourceDir = 'dist';
const PORT = process.env.PORT || 3000;
const WORKERS = process.env.WEB_CONCURRENCY || 1;
throng({
workers: WORKERS,
lifetime: Infinity
}, start);
function start() {
var app = express();
app.use('/static', express.static(staticDir));
app.use(express.static(sourceDir));
app.get('*', (_, res) =>
res.sendFile(join(__dirname, sourceDir, '/index.html'))
);
app.listen(PORT, () => {
console.log(`Express server listening on port ${PORT} on ${WORKERS} worker(s)`);
console.log(`Serving content from /${sourceDir}/`);
});
}
}).call(this);