forked from net9/accounts9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.coffee
executable file
·91 lines (76 loc) · 2.14 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
#!/usr/bin/env coffee
# Module dependencies
messages = require "./messages"
config = require "./config"
express = require "express"
MongoStore = (require "connect-mongo") express
fs = require "fs"
util = require "util"
# Configuration
app = module.exports = express.createServer()
accessLogfile = fs.createWriteStream config.log.access, flags: "a"
errorLogfile = fs.createWriteStream config.log.error, flags: "a"
app.configure ->
app.use express.logger(stream: accessLogfile)
app.set "views", __dirname + "/views"
app.set "view engine", "ejs"
app.use express.bodyParser()
app.use express.methodOverride()
app.use express.cookieParser()
app.use express.session(
secret: config.cookieSecret
store: new MongoStore(
db: config.db.name
host: config.db.host
port: config.db.port
)
)
app.use app.router
app.use express.router require("./routes")
app.use express.router require("./oauth")
app.use express.router require("./user")
app.use express.router require("./app/")
app.use express.router require("./group")
app.use express.router require("./interface")
app.use express.static __dirname+"/public"
app.configure "development", ->
app.use express.errorHandler(
dumpExceptions: true
showStack: true
)
app.use express.logger()
app.configure "production", ->
app.error (err, req, res, next) ->
meta = "[" + new Date() + "] " + req.url + "\n"
errorLogfile.write meta
errorLogfile.write err.stack
errorLogfile.write "\n"
next()
# Helper functions for view rendering
app.helpers
msg: messages.get.bind messages
pageTitle: (title) ->
if title
messages.get "page-title", title
else
messages.get "index-page-title"
inspect: (obj) ->
util.inspect obj
app.dynamicHelpers
curUser: (req, res) ->
req.session.user
error: (req, res) ->
err = req.flash "error"
if err.length
messages.get err
else
null
info: (req, res) ->
succ = req.flash "info"
if succ.length
messages.get succ
else
null
unless module.parent
app.listen 3000
console.log "Express server listening on port %d", app.address().port