-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (31 loc) · 880 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
var config = require('./config')();
var mongoose = require('mongoose');
var Hapi = require('hapi');
var server;
var router = require('./routes/Routes');
var nunjucks = require('nunjucks');
var PORT = process.argv[3] || 80;
var db;
if (process.argv[2]) {
config.setEnv(process.argv[2])
}
mongoose.connect('mongodb://' + config.db.host + '/' + config.db.name);
db = mongoose.connection;
db.on('error', function () {
console.error.bind(console, 'connection error:')
//@ToDO: communicate database problem
});
db.once('open', function callback () {
console.log('mongo connected')
init();
});
function init () {
server = new Hapi.Server(PORT, {
files: {relativeTo: __dirname + 'app'}
});
server.start(function () {
console.log('Server running at:', server.info.uri);
});
router.init(server, __dirname);
router.set();
}