-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.coffee
48 lines (42 loc) · 1.07 KB
/
server.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
express = require 'express'
db = require './app_modules/common/db'
require './app_modules/common/ext'
app = express()
rootPath = process.cwd()
#系统配置
appconfig =
port: 80
#模版引擎
app.set 'view engine', 'jade'
#视图
app.set 'views', rootPath + '\\static\\views'
#静态资源
app.use '/static', express.static(__dirname + '\\static')
#注册模板引擎
app.engine 'jade', require('jade').__express
#首页
app.get '/', (req, res) ->
PersonModel = db.getPersonModel()
PersonModel.find {},successHandler
successHandler = (err, data) ->
allPerson = []
if err
log.error err
else
allPerson = data
res.render 'index', allPerson
#新增一个人页面
app.get '/toAddPerson', (req, res) ->
res.render 'test/person/personAdd'
#新增一个人
app.post '/addPerson', (req, res) ->
PersonModel = db.getPersonModel()
newPersonInfo =
namecd: req.param 'namecn'
age: req.param 'age'
sex: req.param 'sex'
newPerson = new PersonModel newPersonInfo
newPerson.save()
res.redirect '/'
app.listen appconfig.port, () ->
console.log 'app start @' + appconfig.port