forked from xiadd/shorthand
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
59 lines (49 loc) · 1.61 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
53
54
55
56
57
58
59
const AV = require('leanengine');
const express = require('express');
AV.init({
appId: '',
appKey: '',
masterKey: ''
});
//是否启用masterkey
AV.Cloud.useMasterKey();
const app = require('./app/app');
app.use(express.static('./public'));
const PORT = parseInt(process.env.LEANCLOUD_APP_PORT || 3000);
//启动服务器
var isDev = process.env.NODE_ENV === 'dev';
if(isDev){
var webpack = require('webpack'),
webpackDevMiddleware = require('webpack-dev-middleware'),
webpackHotMiddleware = require('webpack-hot-middleware'),
webpackDevConfig = require('./webpackConfig/webpack.dev.config.js');
var compiler = webpack(webpackDevConfig);
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));
// 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(3000, function(){
console.log('App (dev) is now running on port 3000!');
});
} else {
app.listen(PORT, function (err) {
console.log('app is running on port 3000');
// 注册全局未捕获异常处理器
process.on('uncaughtException', function (err) {
console.error("Caught exception:", err.stack);
});
process.on('unhandledRejection', function (reason, p) {
console.error("Unhandled Rejection at: Promise ", p, " reason: ", reason.stack);
});
});
}