forked from bigchaindb/js-reactor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.demo.js
51 lines (42 loc) · 1.59 KB
/
server.demo.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
43
44
45
46
47
48
49
50
51
/* eslint-disable strict, no-console */
/* eslint-disable import/no-extraneous-dependencies, import/newline-after-import */
'use strict';
const path = require('path');
const WebpackDevServer = require('webpack-dev-server');
const webpack = require('webpack');
const config = require('./webpack.config.js');
require('dotenv').load({ silent: true });
const HOST_NAME = process.env.DEMO_HOST_NAME || 'localhost';
const PORT = process.env.DEMO_PORT || 3000;
// Manipulate webpack entry for demo server; only use demo app
config.entry = [path.resolve(__dirname, 'demo/app')];
// Enable hot reloading if on demo mode
if (process.env.NODE_ENV === 'demo') {
config.entry.unshift(`webpack-dev-server/client?http://${HOST_NAME}:${PORT}/`,
'webpack/hot/dev-server');
config.plugins.push(new webpack.HotModuleReplacementPlugin());
// React hot reloading is enabled through .babelrc and babel-react-transform
}
// Specify output location for bundled files
config.output.publicPath = '/assets/';
// Configure server
const compiler = webpack(config);
const server = new WebpackDevServer(compiler, {
publicPath: config.output.publicPath,
contentBase: './demo',
historyApiFallback: {
index: '/'
},
hot: true,
noInfo: true,
stats: { colors: true }
});
// Start server
server.listen(PORT, HOST_NAME, (err) => {
if (err) {
console.error(`Demo server ran into ${err} while starting on ${HOST_NAME}:${PORT}. ` +
'Shutting down...');
server.close();
}
console.log(`Demo server running on ${HOST_NAME}:${PORT}`);
});