forked from nforge/devnote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.coffee
115 lines (93 loc) · 3.69 KB
/
app.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# # profiling code ...
# profiler = require 'nodetime'
# profiler.profile()
# # profiling code ends here...
util = require 'util'
###
Module dependencies.
###
express = require 'express'
routes = require './routes'
wikiApp = require './wikiApp'
userApp = require './userApp'
fileApp = require './fileApp'
adminApp = require './adminApp'
i18n = require './lib/i18n'
i18n.configure
locales: ['en', 'ko']
noop = ->
process.env.uploadDir = uploadDir = __dirname + '/public/attachment'
WIKINAME = 'note'
ROOT_PATH = '/wikis/' + WIKINAME
app = express.createServer()
# Configuration
LISTEN_PORT = 3000
app.set 'views', __dirname + '/views'
app.set 'view engine', 'jade'
oneDay = 60*60*1000*24
app.configure ->
app.use express.bodyParser
uploadDir: uploadDir
app.use express.cookieParser 'n4wiki session'
app.use express.session()
app.use express.methodOverride()
app.use i18n.init
app.use app.router
app.use express.logger 'dev'
# Session-persisted message middleware
app.locals.use (req, res) ->
err = req.session.error
msg = req.session.success
# delete req.session.error
# delete req.session.success
res.locals.message = ''
if err
res.locals.message = err
if msg
res.locals.message = msg
app.configure 'development', ->
app.use express.static __dirname + '/public'
app.use express.errorHandler
dumpExceptions: true,
showStack: true,
app.configure 'production', ->
app.use express.errorHandler()
app.use express.staticCache()
app.use express.static __dirname + '/public', { maxAge: oneDay }
# Routes
app.get '/', routes.index
# Wiki
app.get ROOT_PATH + '/pages', wikiApp.getPages # get page list
app.get ROOT_PATH + '/pages/:name', wikiApp.getPage # get a page
app.get ROOT_PATH + '/new', wikiApp.getNew # get a form to post new wikipage
app.post ROOT_PATH + '/pages', wikiApp.postNew # post new wikipage
app.del ROOT_PATH + '/pages/:name', wikiApp.postDelete # delete wikipage
app.put ROOT_PATH + '/subscribes/:name', wikiApp.postSubscribe # subscribe wikipage
app.del ROOT_PATH + '/subscribes/:name', wikiApp.postUnsubscribe # unsubscribe wikipage
app.post '/api/note/pages/:name', wikiApp.postRollback # wikipage rollback
# Login & Logout
app.post ROOT_PATH + '/users/login', userApp.postLogin # post login
# User
app.get ROOT_PATH + '/users', userApp.getUsers # get user list
app.get ROOT_PATH + '/users/new', userApp.getNew # new user page
app.post ROOT_PATH + '/users/new', userApp.postNew # post new user
app.get ROOT_PATH + '/user/:id', userApp.getId # show user information
app.post ROOT_PATH + '/user/:id', userApp.postId # change user information (password change)
app.post ROOT_PATH + '/dropuser', userApp.postDropuser # drop user
# attachment
app.get ROOT_PATH + '/pages/:name/attachment', fileApp.getAttachment # file attachment page
app.get ROOT_PATH + '/pages/:name/attachment.:format', fileApp.getAttachmentList # file attachment list call by json
app.post ROOT_PATH + '/pages/:name/attachment.:format?', fileApp.postAttachment # file attachment
app.del ROOT_PATH + '/pages/:name/attachment/:filename', fileApp.delAttachment # attachment file delete
# admin
app.get '/admin/mail', adminApp.mail
app.post '/admin/mail', adminApp.postMail
app.get '/admin/mailconf', adminApp.mailconf
app.post '/admin/mailconf', adminApp.postMailconf
exports.start = (port, callback) ->
wikiApp.init WIKINAME
app.listen port
console.log "Express server listening on port %d in %s mode", port, app.settings.env
callback() if callback
exports.stop = -> app.close
exports.start LISTEN_PORT if not module.parent