-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (29 loc) · 1014 Bytes
/
app.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
'use strict';
/* Module Dependencies */
var restify = require('restify'),
versioning = require('restify-url-semver'),
config = require('./config'),
middlewares = require('./api/middlewares'),
errors = require('restify-errors');
/* Initialize Server */
global.server = restify.createServer({
name: config.app.name,
version: config.app.version
});
/* Versioning */
server.pre(versioning());
/* Middleware */
server.use(restify.jsonBodyParser({ mapParams: true }));
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser({ mapParams: true }));
server.use(middlewares.paramParser);
// server.use(restify.fullResponse());
/* Error Handling */
errors.makeConstructor('HTTPException', { statusCode: 500 });
server.on('HTTPException', middlewares.httpException);
/* Routes */
var routes = require('./config/routes')(server);
/* Lift server */
server.listen(config.app.port, function() {
console.log(server.name + ' is now running in port ' + config.app.port);
});