forked from ErickWendel/palestra-impacta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexemplo3-joi.js
33 lines (29 loc) · 900 Bytes
/
exemplo3-joi.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
'use strict';
const Hapi = require('hapi');
const Joi = require('joi');
const server = new Hapi.Server();
server.connection({ port: 3000 });
server.route({
'path': '/',
'method': 'POST',
'config': {
'handler': (req, reply) => {
let dadosTela = req.payload;
var a = new Date()
reply(`Olá Hapi -
nome: ${dadosTela.nome},
telefone: ${dadosTela.telefone}
data de nascimento: ${dadosTela.dataNascimento.toLocaleString()}`);
},
'validate': {
'payload': {
nome: Joi.string().min(0).max(10).required(),
telefone: Joi.number().integer().min(0),
dataNascimento: Joi.date().required()
}
}
}
})
server.start(() => {
console.log('servidor rodando com hapi!!');
})