-
Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathserver.js
42 lines (37 loc) · 1.05 KB
/
server.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
37
38
39
40
41
42
import fs from 'fs';
import path from 'path';
import express from 'express';
import webpack from 'webpack';
import webpackMiddleware from 'webpack-dev-middleware';
import config from './webpack.config.js';
import examplesSSR from './src/examples-ssr.js';
const port = 4114;
const app = express();
const compiler = webpack(config);
const middleware = webpackMiddleware(compiler, {
publicPath: config.output.publicPath,
contentBase: 'src',
stats: {
colors: true,
hash: false,
timings: true,
chunks: false,
chunkModules: false,
modules: false
}
});
app.use(middleware);
app.get('/', function(req, res) {
res.write(fs.readFileSync(path.join(__dirname, 'index.html')));
res.end();
});
app.get('/ssr/', function(req, res) {
res.write(examplesSSR());
res.end();
});
app.listen(port, '0.0.0.0', function(err) {
if (err) {
console.log(err);
}
console.info('==> Listening on port %s. Visit http://localhost:%s/ and http://localhost:%s/ssr in your browser.', port, port, port);
});