How to use `pre` in route handler - hapi.js
pre
should be used inside the config object.
From the route-prerequisites documentation in Hapi:
server.route({
method: 'GET',
path: '/',
config: {
pre: [
[
// m1 and m2 executed in parallel
{ method: pre1, assign: 'm1' },
{ method: pre2, assign: 'm2' }
],
{ method: pre3, assign: 'm3' },
],
handler: function (request, reply) {
return reply(request.pre.m3 + '\n');
}
}
});
Updated Route:
server.route({
method: 'POST',
path: '/searchUser',
config: {
handler: User.searchUser,
pre: [{ method: validate /* function to be called */ }]
}
);