-
Notifications
You must be signed in to change notification settings - Fork 16
/
application.js
63 lines (52 loc) · 2.04 KB
/
application.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
var fs = require("fs");
var _ = require("lodash");
var pkg = require([__dirname, "package"].join("/"));
var logger = require([__dirname, "lib", "logger"].join("/"));
var statsd = require([__dirname, "lib", "statsd"].join("/"));
var Server = require([__dirname, "lib", "server"].join("/"));
module.exports = function(options){
// get configuration options
var configuration = {};
var available_configs = fs.readdirSync([__dirname, "config"].join("/"));
_.each(available_configs, function(config){
var config_name = config.split(".")[0];
configuration[config_name] = require([__dirname, "config", config].join("/"));
});
// set options
var opts = {
disk: _.defaults(_.clone(configuration.default), _.clone(configuration.disk)),
memory: _.defaults(_.clone(configuration.default), _.clone(configuration.memory)),
mongo: _.defaults(_.clone(configuration.default), _.clone(configuration.mongo)),
redis: _.defaults(_.clone(configuration.default), _.clone(configuration.redis)),
s3: _.defaults(_.clone(configuration.default), _.clone(configuration.s3))
}
if(!_.has(opts, options.persistence))
return;
var opts = opts[options.persistence];
delete opts.version;
delete opts["log-level"];
delete opts["api-interface"];
delete opts["api-port"];
var meets_requirements = true;
_.each(opts, function(schema, name){
if(_.has(schema, "required") && schema.required == true && !_.has(options, name))
meets_requirements = false;
});
if(!meets_requirements)
return;
var defaults = {};
_.each(opts, function(schema, name){
defaults[name] = schema.default;
});
_.defaults(options, defaults);
options._ = [options.persistence];
delete options.persistence;
// disable logger
logger.disable();
// init statsd
statsd.initialize(_.pick(options, ["statsd-host", "statsd-port"]));
// return server
var server = new Server(options);
server.version = pkg.version;
return server;
}