-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (39 loc) · 1.18 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
/**
* @file Configure the application.
*/
var restify = require('restify');
var mongoose = require('mongoose');
var config = require('./config/configuration.js');
var logError = require('./config/services.js').logError;
mongoose.connect(config.mongoUrl);
var lib = require('./lib/');
var handlers = lib.handlers;
var middlewares = lib.middlewares;
var server = restify.createServer();
server.use(middlewares.logger);
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(restify.gzipResponse());
server.use(restify.authorizationParser());
server.use(middlewares.injectRedirect);
require("./config/routes.js")(server, handlers);
// Log errors
/* istanbul ignore next */
server.on('uncaughtException', function(req, res, route, err) {
logError(err, req, {
uncaughtRestifyException: true,
statusCode: req.statusCode,
});
if(!res.headersSent) {
if(config.env !== "production") {
res.send(new restify.InternalServerError(err, err.message || 'unexpected error'));
}
else {
res.send(new restify.InternalServerError("An unexpected error occurred :("));
}
return true;
}
return false;
});
module.exports = server;