-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation.js
65 lines (62 loc) · 1.79 KB
/
validation.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
var Hapi = require('hapi');
var Joi = require('joi');
// Create a server with a host and port
var server = Hapi.createServer('127.0.0.1', 8000, {});
// Add the route
server.route([
{
method: 'GET',
path: '/hello/{name}',
config: {
handler: function (req) {
req.reply('hello ' + req.params.name);
},
validate:{
path: {
name: Joi.types.String().regex(/Orlando|Richard|Potato/i)
}
}
}
},
{
method: 'GET',
path: '/people/{id}',
config: {
handler: function (req) {
req.reply('hello ' + req.params.id);
},
validate:{
path: {
id: Joi.types.Number().integer().min(0)
}
}
}
},
{
method: 'PUT',
path: '/people/{id}',
config: {
handler: function (req) {
req.reply('hello ' + req.payload.name);
},
validate:{
path: {
id: Joi.types.Number().integer().min(0)
},
payload:{
id: Joi.types.Number().integer().min(0),
name: Joi.types.String().regex(/Orlando|Richard|Potato/i),
tags: Joi.types.Array().includes('foo', 'bar'),
address: Joi.types.Object({
line1: Joi.types.String().emptyOk(),
line2: Joi.types.String().emptyOk(),
city: Joi.types.String().emptyOk(),
postcode: Joi.types.String().emptyOk()
})
}
}
}
}
]);
// Start the server
server.start();