-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
36 lines (28 loc) · 936 Bytes
/
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
var path = require('path');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.set('port', (process.env.PORT || 3000));
app.use('/', express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// Webpack
var webpack = require('webpack');
var webpackConfig = require('./webpack.config.express.js');
var webpackCompiler = webpack(webpackConfig);
// Webpack middlewares
var webpackDev = require('webpack-dev-middleware');
var webpackHot = require('webpack-hot-middleware');
app.use(webpackDev(webpackCompiler, {
noInfo: true,
publicPath: webpackConfig.output.publicPath
}));
app.use(webpackHot(webpackCompiler));
// Server
app.listen(app.get('port'), 'localhost', function(err) {
if (err) {
console.log(err);
return;
}
console.log('Server started: http://localhost:' + app.get('port') + '/');
});