-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
256 lines (208 loc) · 6.38 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
require('./config/load');
var Config = require('nconf');
var Hoek = require('hoek');
var Glue = require('glue');
var Chalk = require('chalk');
var Db = require('./database');
var Utils = require('./util/utils');
var Boom = require('boom'); // to be removed
// create seneca instance and load actions
require('./actions');
process.title = Config.get('applicationTitle');
var manifest = {
server: {
cache: [
{
name: 'pg-cache',
//engine: require('../catbox-postgres'),
engine: require('catbox-postgres'),
// other specific options for this cache client
partition: Config.get('db:postgres:database'),
user: Config.get('db:postgres:username'),
password: Config.get('db:postgres:password')
},
],
// default connections configuration
connections: {
// controls how incoming request URIs are matched against the routing table
router: {
isCaseSensitive: false,
stripTrailingSlash: true
},
// default configuration for every route.
routes: {
state: {
// determines how to handle cookie parsing errors ("ignore" = take no action)
failAction: "ignore"
},
// disable node socket timeouts (useful for debugging)
timeout: {
server: false,
socket: false
}
}
},
},
connections: [
{
host: "localhost",
port: Config.get("port")
}
],
registrations: [
/* TEMPLATE
{
plugin: {
register: "...",
options: require("./config/plugins/...")
},
options: {}
},
*/
{
plugin: {
register: "good",
options: require("./config/plugins/good")
},
options: {}
},
{
plugin: {
register: "blipp",
options: require("./config/plugins/blipp")
},
options: {}
},
{
plugin: {
register: "inert",
options: {}
},
options: {}
},
{
plugin: {
register: "vision",
options: {}
},
options: {}
},
{
plugin: {
register: "hapi-auth-cookie",
options: {}
},
options: {}
},
{
plugin: {
register: "bell",
options: {}
},
options: {}
},
{
plugin: {
register: "hapi-qs",
options: {}
},
options: {}
},
// dependencies: ["inert"]
{
plugin: {
register: "./plugins/hapi-public/hapi-public.js",
options: require("./config/plugins/hapi-public")
},
options: {}
},
// dependencies: ["hapi-auth-cookie"]
{
plugin: {
register: "hapi-auth-cookie-cache",
options: require("./config/plugins/hapi-auth-cookie-cache")
},
options: {}
},
// dependencies: ["bell", "hapi-auth-cookie-cache"]
{
plugin: {
register: "./plugins/routes-oauth/routes-oauth.js",
options: {}
},
options: {}
},
// dependencies: ["vision", "hapi-auth-cookie-cache"]
// this is where we configure the views manager (using nunjucks) and declare the routes that
// return a view; note that reply.view is only available inside the plugin
{
plugin: {
register: "./plugins/routes-views/routes-views.js",
options: {}
},
options: {}
},
{
plugin: {
register: "./plugins/routes-api/routes-api.js",
options: {}
},
options: {
routes: {
prefix: Config.get("apiPrefix:v1")
}
}
},
// route for the client side app
{
plugin: {
register: "./plugins/initiatives/initiatives.js",
options: {}
},
options: {}
},
{
plugin: {
register: "./plugins/dashboard/dashboard.js",
options: {}
},
options: {}
}
]
};
// TODO: remove good console if not in production
var glueOptions = {
relativeTo: __dirname,
preRegister: function(server, next){
console.log("[glue]: executing preRegister (called prior to registering plugins with the server)")
next();
},
preConnections: function(server, next){
console.log("[glue]: executing preConnections (called prior to adding connections to the server)")
next();
}
};
Glue.compose(manifest, glueOptions, function (err, server) {
Hoek.assert(!err, 'Failed registration of one or more plugins: ' + err);
// start the server and finish the initialization process
server.start(function(err) {
// server.ext('onPreAuth', function (request, reply) {
// var err = Boom.unauthorized(null, 'cookie');
// return reply(err);
// });
Hoek.assert(!err, 'Failed server start: ' + err);
// make the server object available for the methods in the ./util/utils module
Utils.registerServer(server);
// show some informations about the server
console.log(Chalk.green('================='));
console.log("Hapi version: " + server.version);
console.log('host: ' + server.info.host);
console.log('port: ' + server.info.port);
console.log("process.env.NODE_ENV: ", process.env.NODE_ENV);
Db.query("SELECT version()")
.then(function(result){
console.log("database: ", result[0].version);
console.log(Chalk.green('================='));
});
});
});