forked from Cordazar/crest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (47 loc) · 1.16 KB
/
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
55
56
/**
* Copyright 2013 Ricard Aspeljung. All Rights Reserved.
*
* server.js
* crest
*/
var fs = require("fs"),
mongodb = require("mongodb"),
restify = module.exports.restify = require("restify");
var DEBUGPREFIX = "DEBUG: ";
var config = {
"db": {
"port": 27017,
"host": "localhost"
},
"server": {
"port": 3500,
"address": "0.0.0.0"
},
"flavor": "mongodb",
"debug": false
};
var debug = module.exports.debug = function (str) {
if (config.debug) {
console.log(DEBUGPREFIX + str);
}
};
try {
config = JSON.parse(fs.readFileSync(process.cwd() + "/config.json"));
} catch (e) {
debug("No config.json file found. Fall back to default config.");
}
module.exports.config = config;
var server = restify.createServer({
name: "crest"
});
server.acceptable = ['application/json'];
server.use(restify.acceptParser(server.acceptable));
server.use(restify.bodyParser());
server.use(restify.fullResponse());
server.use(restify.queryParser());
server.use(restify.jsonp());
module.exports.server = server;
require('./lib/rest');
server.listen(config.server.port, function () {
console.log("%s listening at %s", server.name, server.url);
});