-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
88 lines (82 loc) · 2.17 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
var Hapi = require('hapi');
var Good = require('good');
// var routes = require("./routes/routes.js");
var server = Hapi.createServer(process.env.PORT || 8080, {
debug: {
request: ['error']
}
});
var dbOpts = {
"url": "mongodb://neapolitan:[email protected]:10081/neapolitan1",
"settings": {
"db": {
"native_parser": false
}
}
};
var goodOpts = {
extendedRequests: true,
logRequestHeaders: true,
//logRequestPayload: true,
//logResponsePayload: true,
opsInterval: 1000,
reporters: [{
//reporter: Good.GoodConsole
//}, {
reporter: Good.GoodFile,
args: ['./fixtures/log_awesome', {
events: {
ops: '*'
}
}]
}, {
reporter: require('good-http'),
args: ['http://localhost:8081', {
events: {
error: '*',
ops: '*'
},
threshold: 500,
wreck: {
headers: { 'x-api-key' : 12345 }
}
}]
// }, {
// reporter: require('good-console')
}]
};
server.views({
engines: {
jade: require("jade")
},
path: "./views"
});
//have plugins in the server pack is because it is modulized
// so it makes sense to put it in the server.pack
server.pack.register([
{ plugin: require('bell')},
{ plugin: require('hapi-auth-cookie')},
{ plugin: require('hapi-mongodb'), options: dbOpts},
// { plugin: require('good'), options: goodOpts},
{ plugin: require('./plugins/server')}], function (err) {
if (err) throw err;
server.route([{
path: '/',
method: 'GET',
config: { // try with redirectTo disabled makes isAuthenticated usefully available
auth: {
strategy: 'session',
mode: 'try'},
plugins: { 'hapi-auth-cookie': { redirectTo: false } }
},
handler: function (request, reply) {
reply.redirect ("/articles");
}
}]);
});
server.start(function (err) {
if (err) {
console.log('error message ' + err);
}
console.log('Hapi server started @ ' + server.info.uri);
});