-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
executable file
·52 lines (40 loc) · 1.35 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
43
44
45
46
47
48
49
50
51
52
/*eslint-env node*/
import express from 'express';
import webpack from 'webpack';
import history from 'connect-history-api-fallback';
import portNumber from 'port-number';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import devConfig from './webpack/webpack.dev.config.babel.js';
const env = process.env.NODE_ENV;
const isDeveloping = env !== 'production';
const port = process.env.PORT ? process.env.PORT : portNumber();
const ip = isDeveloping ? '0.0.0.0' : '0.0.0.0';
const app = express();
app.use( history() );
if( isDeveloping ) {
const compiler = webpack( devConfig );
app.use( webpackDevMiddleware( compiler, {
publicPath: devConfig.output.publicPath,
headers: { 'Access-Control-Allow-Origin': '*' },
stats: {
colors: true,
hash: false,
timings: true,
chunks: false,
chunkModules: false,
modules: false
}
}) );
app.use( webpackHotMiddleware( compiler ) );
// Serve pure static assets
app.use( express.static( './static' ) );
} else {
app.use( express.static( __dirname + '/dist' ) );
}
app.listen( port, ip, error => {
if ( error ) throw error;
/*eslint-disable no-console */
console.info( `[${env}] Listening on port ${port}. Open up http://${ip}:${port}/ in your browser.` );
/*eslint-enable no-console */
});