-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhapi-failaction-example.js
46 lines (42 loc) · 1.16 KB
/
hapi-failaction-example.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
var Hapi = require('hapi'); https://github.com/nelsonic/learn-hapi
var Inert = require('inert');
var Joi = require('joi');
var server = new Hapi.Server({ debug: false })
var register_fields = {
email : Joi.string().email().required(),
name : Joi.string().alphanum().min(1).required()
};
function register_handler(request, reply, source, error) {
console.log(request.payload);
console.log(' - - - - - - - - - - - - - - - - - - - - -');
console.log(source)
console.log(' - - - - - - - - - - - - - - - - - - - - -');
console.log(error)
return reply('welcome!');
}
server.connection({ port: process.env.PORT || 8000 });
server.register(Inert, function (err) {
if (err) { console.error('Failed to load plugin: ', err); }
// console.log(__dirname + '/index.html');
server.route([{
method: 'GET',
path: '/',
handler: {
file: __dirname + '/index.html'
}
},
{
method: '*',
path: '/register',
config: {
validate: {
payload : register_fields,
failAction: 'log'
}
},
handler: register_handler
}]);
});
server.start(function() {
console.log('Visit: http://127.0.0.1:'+server.info.port);
});