-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.js
37 lines (34 loc) · 859 Bytes
/
sample.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
var router = require("express").Router();
const { celebrate, Joi } = require("celebrate");
// Corresopnds to a GET request to /api/sample/
router.get(
"/",
celebrate({
body: Joi.object().keys({
name: Joi.string().required(),
age: Joi.number().integer(),
role: Joi.string().default("admin")
})
}),
function(req, res) {
console.log("HI");
res.send("Hello world!");
}
);
router.post(
"/signup",
celebrate({
body: Joi.object().keys({
name: Joi.string().required(),
age: Joi.number().integer(),
role: Joi.string().default("admin")
})
}),
(req, res) => {
res.send("HI");
console.log(req.body);
// At this point, req.body has been validated and
// req.body.role is equal to req.body.role if provided in the POST or set to 'admin' by joi
}
);
module.exports = router;