-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
90 lines (57 loc) · 1.8 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
var Hapi = require('hapi');
var path = require('path');
require('app-module-path').addPath(__dirname);
const Bootstrap = require('./Utils/BootStrap');
var routes = require("./Routes"); //loading routes
const dbConfig = require('./Config/dbconfig'); //loading configurations
var server = new Hapi.Server();
const Mongoose = require('mongoose');
Mongoose.Promise = require('bluebird');
Mongoose.connect(dbConfig.mongo.URI, function (err) {
if (err) {
console.log("DB Error: ", err);
process.exit(1);
} else {
console.log('MongoDB Connected');
init();
}
});
server.connection({port : 3003, host : 'localhost'});
//swagger
const Pack = require("./package");
const options = {
info: {
'title': 'ERP API Documentation',
'version': Pack.version,
}
};
const HapiSwagger = require("hapi-swagger");
server.register([require('inert'), require('vision'), { 'register' : HapiSwagger, 'options' : options } ], throwIfError);
function throwIfError(err){
//a callback function to throw error if there is an error
if(err){
throw err;
}
}
//registering routes
server.route(routes);
function init()
{
Bootstrap.bootstrapAdmin(function (err, message) {
if (err) {
console.log('Error while bootstrapping version : ' + err)
} else {
console.log(message);
}
});
server.start(function(err){
if(err){
console.log("Error in starting server: ");
console.log(err);
}else{
console.log('Server running at:', server.info.uri);
// console.log(`Server started at ${host}:${port}`);
}
});
}