-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
56 lines (48 loc) · 1.51 KB
/
server.js
File metadata and controls
56 lines (48 loc) · 1.51 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var path = require('path');
var express = require('express');
var app = express();
var PORT = process.env.PORT || 8080;
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var webpack = require('webpack');
var config = require('./webpack.config');
var compiler = webpack(config);
app.get('/*', function(req, res, next) {
res.header(
'Content-Security-Policy',
'sandbox allow-scripts allow-same-origin;'
);
res.header('X-Frame-Options', 'deny');
res.header('X-XSS-Protection', '1; mode=block');
res.header('Referrer-Policy', 'no-referrer');
res.header('X-Permitted-Cross-Domain-Policies', 'none');
next();
});
app.use(
webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: config.output.publicPath
})
);
app.use(webpackHotMiddleware(compiler));
app.use(express.static(path.join(__dirname, 'dist')));
app.get('/', function(request, response) {
response.sendFile(__dirname + '/dist/index.html');
});
app.get('/web', function(request, response) {
response.sendFile(__dirname + '/dist/index.web.html');
});
app.get('/web/worker.web.js', function(request, response) {
response.sendFile(__dirname + '/dist/worker.web.js');
});
app.listen(PORT, function(error) {
if (error) {
console.error(error);
} else {
console.info(
'==> 🌎 Listening on port %s. Visit http://localhost:%s/ in your browser.',
PORT,
PORT
);
}
});