forked from sensebox/EASIN-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (34 loc) · 1021 Bytes
/
index.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
'use strict';
var cfg = require('./config');
var restify = require('restify');
var routes = require('./routes');
var mongoose = require('mongoose');
mongoose.connect('mongodb://'+cfg.mongo.server+':'+cfg.mongo.port+'/'+cfg.mongo.collection,{
user: cfg.mongo.dbuser,
pass: cfg.mongo.dbpass
});
var db = mongoose.connection;
db.on('error', function(){
console.error.bind(console, 'connection error:')
});
db.once('open', function(callback){
var server = createServer();
routes.SetupRoutes(server,cfg.server.path);
server.listen(cfg.server.port, function () {
console.log('%s listening at %s', server.name, server.url);
});
});
db.on('close', function(callback){
console.log("connection close");
process.exit();
});
function createServer(){
var server = restify.createServer({
name: cfg.server.name,
version: cfg.server.version
});
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
return server;
}