-
Notifications
You must be signed in to change notification settings - Fork 107
/
solution.js
31 lines (28 loc) · 817 Bytes
/
solution.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
const Hapi = require('@hapi/hapi');
const Joi = require('@hapi/joi');
(async () => {
try {
const server = Hapi.Server({
host: 'localhost',
port: Number(process.argv[2] || 8080)
});
server.route({
method: 'POST',
path: '/login',
config: {
handler: (request, h) => 'authentification réussie',
validate: {
payload: Joi.object({
isGuest: Joi.boolean().required(),
username: Joi.string().when('isGuest', { is: false, then: Joi.required() }),
password: Joi.string().alphanum(),
accessToken: Joi.string().alphanum()
}).options({ allowUnknown: true }).without('password', 'accessToken')
}
}
});
await server.start();
} catch (error) {
console.log(error);
}
})();