I want every hapi route path to start with a prefix (/api/1
) without adding it to each route. Is this possible?
The following route should be available with path /api/1/pets
and not /pets
const Hapi = require('hapi');
const server = new Hapi.Server();
server.route({
method: 'GET',
path: '/pets'
})
Seems you can't do it globally for the whole application. But there's a possibility to add prefixes for all the routes defined inside a plugin:
server.register(require('a-plugin'), {
routes: {
prefix: '/api/1'
}
});
Hope this helps.
Just in case, if you're gonna try to add base path via events for new routes, it's not gonna work.
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