forked from apiaryio/apiblueprintorg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.coffee
50 lines (36 loc) · 1.16 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
# Configuration
config = require './lib/config'
# System libraries
express = require 'express'
http = require 'http'
logger = require 'morgan'
# Logging
logging = require('./lib/logging')
log = logging.get 'index'
logExpressError = logging.get 'express/error'
# Export
module.exports = new (require 'events').EventEmitter()
# Express Server
apiServer = express()
apiServer.disable 'x-powered-by'
# logger
if process.env.NODE_ENV is 'development'
apiServer.use logger('dev')
# api controller
apiModule = require './lib/controllers/api'
apiModule.setup(apiServer)
# Set up error handlers last; yeah, really, they need to be AFTER the controllers :(
apiServer.use logExpressError
# catch EXCEPTIONS...
process.on 'uncaughtException', (err) ->
console.trace 'APIBLUEPRINT_EXCEPTION_UNCAUGHT: ', err
log.error 'Uncaught exception: ', err
port = process.env.PORT * 1
# Instance
module.exports.instance = apiServer
module.exports.instance.listen port, (err) ->
if err
log.error 'Unable to start api.apiblueprint.org server', err
log.info "Started server on port #{port}"
log.debug 'Application started'
module.exports.emit 'start'