-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
131 lines (109 loc) · 2.76 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Created by srinath on 27/12/15.
*/
'use strict';
const config = require('./config');
const Hapi = require('hapi');
const Vision = require('vision');
const Ejs = require('ejs');
const Good = require('good');
const chairo = require('chairo');
const inert = require('inert');
//const _ = require('underscore');
const KongApiSyncPlugin = require('./plugins/kong-api-sync');
const StaticRoutes = require("./routes/static");
const DefaultRoutes = require("./routes/default");
const LoginRoutes = require("./routes/login");
const RegisterRoutes = require("./routes/register");
const server = new Hapi.Server();
//setting application port
server.connection({
port: config.port
});
server.register({
register: chairo
}, err => {
if (err) {
return;
}
server.seneca
.use('seneca-amqp-transport', {
amqp: {
url: config.amqpServiceHost
}
})
.client({
type: 'amqp',
pin: 'role:mail'
});
/*.use('mesh', { auto:true, pin:'role:auth' });
.client({
type: 'tcp',
host: config.mailingServiceHost,
port: config.mailingServicePort,
pin: 'role:mail'
});*/
});
//registering view plugin
server.register(Vision, (err) => {
if (err) {
throw err;
}
server.views({
engines: {
ejs: Ejs
},
relativeTo: __dirname,
path: 'views',
layout: true
});
server.route({
method: 'GET',
path: '/ping',
handler: function (request, reply) {
reply('pong');
}
});
StaticRoutes.use(server);
DefaultRoutes.use(server);
LoginRoutes.use(server);
RegisterRoutes.use(server);
server.register({
register: KongApiSyncPlugin.register,
options: {
sync: true,
apis: [{
name: 'Authentication',
strip_request_path: true,
request_path: '/authentication/'
}]
}
}, function (err, next) {
if (err) {
console.info("synchronizing upstream url with kong failed, " + err);
console.error(err);
throw err;
}
console.log('Synchronized API with kong');
next();
});
server.register({
register: Good,
options: {
reporters: [{
reporter: require('good-console'),
events: {
response: '*',
log: '*'
}
}]
}
}, (err) => {
if (err) {
throw err; // something bad happened loading the plugin
}
server.start(() => {
server.log('info', 'Server running at: ' + server.info.uri);
});
});
});