-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (28 loc) · 1010 Bytes
/
server.js
File metadata and controls
32 lines (28 loc) · 1010 Bytes
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
/*
* @Author: ihoey
* @Date: 2018-04-27 10:51:18
* @Last Modified by: ihoey
* @Last Modified time: 2018-04-27 10:51:18
*/
const AV = require('leanengine')
const app = require('./app')
// 端口一定要从环境变量 `LEANCLOUD_APP_PORT` 中获取。
// LeanEngine 运行时会分配端口并赋值到该变量。
const PORT = parseInt(process.env.LEANCLOUD_APP_PORT || process.env.PORT || 3000)
AV.init({
appId: process.env.LEANCLOUD_APP_ID,
appKey: process.env.LEANCLOUD_APP_KEY,
masterKey: process.env.LEANCLOUD_APP_MASTER_KEY,
})
// 如果不希望使用 masterKey 权限,可以将下面一行删除
AV.Cloud.useMasterKey()
app.listen(PORT, err => {
console.log('Node app is running on port:', PORT)
// 注册全局未捕获异常处理器
process.on('uncaughtException', err => {
console.error('Caught exception:', err.stack)
})
process.on('unhandledRejection', (reason, p) => {
console.error('Unhandled Rejection at: Promise ', p, ' reason: ', reason.stack)
})
})