forked from ekristen/docker-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
66 lines (54 loc) · 1.62 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var config = require('config');
var restify = require('restify');
var bunyan = require('bunyan');
var restify_endpoints = require('restify-endpoints');
// Setup logger
var logger = bunyan.createLogger({
name: 'docker-index',
stream: process.stdout,
level: config.loglevel,
src: true,
serializers: {
req: bunyan.stdSerializers.req
}
});
// Setup Redis Connection
var redis = require('redis').createClient(config.redis.port, config.redis.host);
redis.on('error', function(err) {
logger.error({domain: 'redis', err: err, stack: err.stack});
});
// Setup Restify Endpoints
var endpoints = new restify_endpoints.EndpointManager({
endpointpath: __dirname + '/endpoints',
endpoint_args: [config, redis, logger]
});
// Create our Restify server
var server = restify.createServer({
name: 'docker-index',
version: '1.0.0'
});
// Catch unhandled exceptions and log it!
server.on('uncaughtException', function (req, res, route, err) {
logger.error({err: err}, 'uncaughtException');
});
// Basic Restify Middleware
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
// Important so that application/json does not override
// parameters passed via the url.
server.use(restify.bodyParser({
mapParams: false,
overrideParams: false
}));
// Audit logging to stdout via bunyan
server.on('after', restify.auditLogger({
log: logger
}));
// Attach our endpoints
endpoints.attach(server);
// Listen
server.listen(config.app.port, function () {
console.log('%s listening at %s', server.name, server.url);
});
require('./lib/firsttime.js')(config, redis);
require('./lib/upgrades.js')(config, redis);