-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexpress.js
32 lines (25 loc) · 965 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
32
const express = require('express'); // eslint-disable-line
const compression = require('compression'); // eslint-disable-line
const app = express();
const basedir = __dirname + '/src/'; // eslint-disable-line
app.use(compression());
function getSourcesPath(_request) {
return basedir;
}
app.use('/fm/', (req, res, next) => {
express.static(getSourcesPath(req))(req, res, next);
});
app.use('/', (req, res, next) => {
express.static(getSourcesPath(req))(req, res, next);
});
app.get(/.*service-worker\.js/, function(req, res) {
res.sendFile(getSourcesPath(req) + 'service-worker.js');
});
app.get('[^.]+', function(req, res) {
// handles app access using a different state path than index (otherwise it will not return any file)
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
res.sendFile(getSourcesPath(req) + 'index.html');
});
app.listen(8080);