-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
54 lines (43 loc) · 902 Bytes
/
server.js
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
'use strict'
/**
* NPM modules.
*/
var bodyParser = require('body-parser')
, connect = require('connect')
, connectRoute = require('connect-route')
/**
* Local modules.
*/
var logger = require('./logger')
logger.debug('Starting server..')
var authMiddleware = require('./auth-middleware')
, errorMiddleware = require('./error-middleware')
, loggerMiddleware = require('./logger-middleware')
, views = require('./views')
var app = connect()
/**
* Request logging.
*/
app.use(loggerMiddleware())
/**
* Parse the incoming request body as json.
*/
app.use(bodyParser.json())
/**
* Authentication.
*/
app.use(authMiddleware())
/**
* Routing.
*/
app.use(connectRoute(views))
/**
* Error handling.
*/
app.use(errorMiddleware())
/**
* Server start.
*/
app.listen(process.env.npm_config_port ||
process.env.PORT ||
process.env.npm_package_config_port)