UNPKG

makemehapi

Version:

Self guided workshops to teach you about hapi.

30 lines (25 loc) 777 B
var Hapi = require('hapi'); var Joi = require('joi'); var server = new Hapi.Server(); server.connection({ host: 'localhost', port: Number(process.argv[2] || 8080) }); server.route({ method: 'POST', path: '/login', config: { handler: function (request, reply) { reply('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') } } }); server.start(function () {});