makemehapi
Version:
Self guided workshops to teach you about hapi.
32 lines (28 loc) • 808 B
JavaScript
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) => 'login successful',
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);
}
})();