-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.coffee
89 lines (71 loc) · 2.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
# initial requires (set up coffeescript stuff)
require('./server/lib/bootstrap')
bodyParser = require('body-parser')
config = require('config')
cookieParser = require('cookie-parser')
express = require('express')
favicon = require('serve-favicon')
fs = require('fs')
http = require('http')
https = require('https')
loggly = require('winston-loggly')
morgan = require('morgan')
passport = require('passport')
raven = require('raven')
requireDir = require('require-dir')
winston = require('winston')
Handler = require(App.path('server/api/1/handler'))
LocalStrategy = require('passport-local').Strategy
RavenLogger = App.lib('ravenLogger')
# require and initialize modules
Db = App.module('database').initialize
uri: config.get('db.uri')
Emailer = App.module('emailer').initialize
host: config.get('email.host')
secure: config.get('email.secure')
port: config.get('email.port')
user: config.get('email.user')
pass: config.get('email.password')
from: config.get('email.from')
enable: config.get('email.enable')
Logger.add(winston.transports.Console, level: config.get('logging.consoleLevel'))
if config.get('logging.logglyLevel') != 'silent'
Logger.add loggly.Loggly,
level: config.get('logging.logglyLevel')
subdomain: config.get('logging.logglySubdomain')
inputToken: config.get('logging.logglyToken')
json: true
stripColors: true
if config.get('logging.ravenLevel') != 'silent'
ravenClient = new raven.Client(config.get('logging.sentryDSN'))
Logger.add RavenLogger,
level: config.get('logging.ravenLevel')
raven: ravenClient
Promise.onPossiblyUnhandledRejection (err, promise) ->
Logger.error(err)
Promise.longStackTraces()
app = express()
# do not log url parameters
morgan.token('url', (req, res) -> req.path)
loggerStream =
write: (message) ->
Logger.info(message.trim())
# this is exactly the dev format, minus the colours
loggerFormat = ':method :url :status :response-time ms - :res[content-length]'
app.set('port', Number(process.env.PORT || config.get('server.port')))
app.use(morgan(loggerFormat, stream: loggerStream))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded(extended: true))
app.use(cookieParser(config.get('secret')))
app.use(favicon(App.path(config.get('paths.staticPath'), '/favicon.ico')))
app.use(express.static(App.path(config.get('paths.staticPath'))))
passport.use(Db.User.createStrategy())
passport.serializeUser(Db.User.serializeUser())
passport.deserializeUser(Db.User.deserializeUser())
app.use passport.initialize
userProperty: 'me'
app.use(passport.authenticate('token'))
Handler.listenAll(app)
server = http.createServer(app)
server.listen app.get('port'), ->
Logger.debug('Express server listening on port ' + app.get('port'))