-
Notifications
You must be signed in to change notification settings - Fork 68
/
hellogood.js
68 lines (58 loc) · 1.85 KB
/
hellogood.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
/**
Good is currently not compatible with Hapi v17,
so this example is using Hapi v16
**/
/**
Start this app from your command line with:
node examples/hellogood.js
then visit: http://localhost:3000/hello/YOURNAME
*/
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({
host: '0.0.0.0',
port: 3000
});
server.route({
method: 'GET',
path: '/hello/{name*}',
handler: function(request, reply) {
// log the request
request.log(['name'], request.params.name + ' (request.log)');
// use request.log instead of console.log:
request.log('info', {my: 'object', has: 'many', props: { hello: request.params.name } });
// server.log(['name'], request.params.name + ' requested / ' + '(server.log)');
return reply('Hello ' + request.params.name);
}
})
const options = {
ops: {
interval: 30000 // reporting interval (30 seconds)
},
reporters: {
myConsoleReporter: [{
// good-squeeze allows filtering events based on the `good` event options
// @see https://github.com/hapijs/good/blob/master/API.md#event-types
module: 'good-squeeze', // https://github.com/hapijs/good-squeeze
name: 'Squeeze',
// @example "Log everything"
args: [{ log: '*', error: '*', response: '*', request: '*', ops: '*' }]
// @example "Log only request logs with a certain tag":
// args: [{ request: ['name'] }]
}, {
module: 'good-console'
}, 'stdout']
}
};
server.register({
register: require('good'),
options,
}, function (err) {
if (err) {
return console.error(err);
}
server.start(function () {
console.log('Now Visit: http://localhost:' + server.info.port + '/YOURNAME');
console.dir(server.info);
});
});