-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (47 loc) · 1.81 KB
/
app.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
53
54
55
56
57
58
59
60
61
var express = require('express');
var path = require('path');
var consolidate = require('consolidate');
var open = require('./server/models/open');
var isDev = process.env.NODE_ENV !== 'production';
var app = express();
var port = 3000;
app.engine('html', consolidate.ejs);
app.set('view engine', 'html');
app.set('views', path.resolve(__dirname, './server/views'));
// local variables for all views
app.locals.env = process.env.NODE_ENV || 'dev';
app.locals.reload = true;
if (isDev) {
// static assets served by webpack-dev-middleware & webpack-hot-middleware for development
var webpack = require('webpack'),
webpackDevMiddleware = require('webpack-dev-middleware'),
webpackHotMiddleware = require('webpack-hot-middleware'),
webpackDevConfig = require('./webpack.config.js');
var compiler = webpack(webpackDevConfig);
// attach to the compiler & the server
app.use(webpackDevMiddleware(compiler, {
// public path should be the same with webpack config
publicPath: webpackDevConfig.output.publicPath,
noInfo: true,
stats: {
colors: true
}
}));
app.use(webpackHotMiddleware(compiler));
require('./server/routes')(app);
// add "reload" to express, see: https://www.npmjs.com/package/reload
var reload = require('reload');
var http = require('http');
var server = http.createServer(app);
reload(server, app);
server.listen(port, '0.0.0.0', function(){
console.log('App (dev) is now running on port 3000!');
});
} else {
// static assets served by express.static() for production
app.use(express.static(path.join(__dirname, 'dist')));
require('./server/routes')(app);
app.listen(port, function () {
console.log('App (production) is now running on port 3000!');
});
}