UNPKG

1.08 kBJavaScriptView Raw
1import fs from 'fs';
2import path from 'path';
3import express from 'express';
4import webpack from 'webpack';
5import webpackMiddleware from 'webpack-dev-middleware';
6import config from './webpack.config.js';
7
8import examplesSSR from './src/examples-ssr.js';
9
10const port = 4114;
11const app = express();
12
13const compiler = webpack(config);
14const middleware = webpackMiddleware(compiler, {
15 publicPath: config.output.publicPath,
16 contentBase: 'src',
17 stats: {
18 colors: true,
19 hash: false,
20 timings: true,
21 chunks: false,
22 chunkModules: false,
23 modules: false
24 }
25});
26
27app.use(middleware);
28app.get('/', function(req, res) {
29 res.write(fs.readFileSync(path.join(__dirname, 'index.html')));
30 res.end();
31});
32app.get('/ssr/', function(req, res) {
33 res.write(examplesSSR());
34 res.end();
35});
36
37app.listen(port, '0.0.0.0', function(err) {
38 if (err) {
39 console.log(err);
40 }
41 console.info('==> Listening on port %s. Visit http://localhost:%s/ and http://localhost:%s/ssr in your browser.', port, port, port);
42});