forked from galenmaly/lighterpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·78 lines (68 loc) · 2.21 KB
/
app.js
File metadata and controls
executable file
·78 lines (68 loc) · 2.21 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const compression = require('compression');
const config = require('config');
const express = require('express');
const app = express();
app.enable('trust proxy');
const oneDay = 86400000;
app.use(compression());
app.use(cookieParser());
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({
extended: true,
limit: '50mb',
}));
app.use(express.static(`${__dirname}/public/`, { maxAge: oneDay }));
const endpoints = require('./server/endpoints.js');
const moderationEndpoints = require('./server/moderation-endpoints.js');
const views = require('./server/views.js');
app.use('/', endpoints);
app.use('/', moderationEndpoints);
app.use('/', views);
console.log('-------');
console.log(new Date().toString().substr(0, 24));
if (config.get('environment') === 'production') {
webpackConfig = require('./webpack.config');
} else {
webpackConfig = require('./webpack.development.config');
}
webpackCompiler = webpack(webpackConfig);
// Default port is 3000; we can have multiple bindings
config.get('bindings').map(
(bind) => {
app.listen(config.get('port'), bind);
console.log(`Listening on [${bind}]:${config.get('port')}`);
},
);
if (config.get('environment') !== 'production') {
new WebpackDevServer(webpack(webpackConfig), {
historyApiFallback: true,
disableHostCheck: true,
publicPath: webpackConfig.output.publicPath,
hot: true,
proxy: {
'*': {
target: `http://localhost:${config.get('port')}`,
secure: false,
changeOrigin: true,
},
},
stats: {
cached: false,
cachedAssets: false,
colors: { level: 2 },
},
watchOptions: {
aggregateTimeout: 300,
poll: 1000,
},
}).listen(config.get('devServerPort'), (err, result) => {
if (err) {
return console.log(err);
}
console.log(`Webpack dev server listening on port ${config.get('devServerPort')}`);
});
}