forked from noman798/leancloud_798
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.coffee
57 lines (41 loc) · 1.18 KB
/
init.coffee
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
global.AV = require('leanengine')
APP_ID = process.env.LC_APP_ID
APP_KEY = process.env.LC_APP_KEY
MASTER_KEY = process.env.LC_APP_MASTER_KEY
AV.initialize(APP_ID, APP_KEY, MASTER_KEY)
AV.Cloud.useMasterKey()
require('rootpath')()
require("cloud/_redis")
require('cloud/init')
require('route/init')
app = require('app')
app.use AV.Cloud
cookieParser = require('cookie-parser')
bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(cookieParser())
app.use (req, res, next) ->
err = new Error('Not Found')
err.status = 404
next err
return
if app.get('env') == 'development'
require 'test'
app.use (err, req, res, next) ->
res.status err.status or 500
res.render 'error',
message: err.message
error: err
return
# 如果是非开发环境,则页面只输出简单的错误信息
app.use (err, req, res, next) ->
res.status err.status or 500
res.render 'error',
message: err.message
error: {}
return
PORT = parseInt(process.env.LC_APP_PORT || 3000)
server = app.listen(PORT,->
console.log('Node app is running, port:', PORT)
)