forked from Druadach/Valine-Admin
-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
37 lines (28 loc) · 1.02 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
'use strict'
const process = require('node:process')
const AV = require('leanengine')
const dotenv = require('dotenv')
dotenv.config()
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()
const app = require('./app')
// 端口一定要从环境变量 `LEANCLOUD_APP_PORT` 中获取。
// LeanEngine 运行时会分配端口并赋值到该变量。
const PORT = Number.parseInt(process.env.LEANCLOUD_APP_PORT || process.env.PORT || 3000)
app.listen(PORT, (err) => {
if (err)
console.error('app error:', 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)
})
})