-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpress.js
36 lines (28 loc) · 1.07 KB
/
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
33
34
35
36
const express = require('express'); // eslint-disable-line
const compression = require('compression'); // eslint-disable-line
const browserCapabilities = require('browser-capabilities'); // eslint-disable-line
const app = express();
const basedir = __dirname + '/src/'; // eslint-disable-line
app.use(compression());
function getSourcesPath(request) {
let clientCapabilities = browserCapabilities.browserCapabilities(request.headers['user-agent']);
clientCapabilities = new Set(clientCapabilities); // eslint-disable-line
if (clientCapabilities.has('modules')) {
return basedir;
} else {
return basedir;
}
}
app.use('/menu/', (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.use((req, res) => {
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);