Very new to Hapi framework. I am trying to make custom error pages. How do you route a 404.html page to 404 response?
would like the handler to be like so
handler: function (request, reply) {
reply.file('./static/website/javascript/main.js');
}
You could use something like this:
server.route({
method: '*',
path: '/{p*}', // catch-all path
handler: function (request, reply) {
reply.file('./path/to/404.html').code(404);
}
});
By using the .code()
method, you can override the default (200 OK) status code.
A small update: since 9.x version you need to include Inert plugin to use reply.file
. See this issue: https://github.com/hapijs/hapi/issues/2729
(By this time documentation is not updated yet)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With