Reputation: 1235
I'm really new to Node.js. Currently I'm using Hapi.js.
Based on Hapi.js documentation, the sample provided is to hardcoded the path to a handler.
Is it possible to map dynamically generated path to a handler?
For example: I have a server route that receives * path, based on the path value, I will go find that particular item in the file and reply it back to user.
The reason of me doing this is that, if I hardcoded the path with handler, every time I have changed the file name, I need to manually update the path. This will be very troublesome.
Upvotes: 0
Views: 1145
Reputation: 42048
See the File handler and Directory handler sections in the tutorial. A sample code for a directory handler:
server.route({
method: 'GET',
path: '/{param*}',
handler: {
directory: {
path: 'public'
}
}
});
Upvotes: 2