In fastify, is there a way I can add an alias to a route/ path? Basically, having two paths be handled the same way. This is useful for migrating an APIs.
I understand that I can abstract the handler function into a named function, and pass that function to both routes. I am just wondering if there's another way to do so?
No, there is not the feature to set an array of routes to one handler (here the registration logic if you would like to add this feature).
I would suggest registering routes like this:
['/', '/alias'].forEach(path => {
fastify.route({
method: ['GET'], // you could define multiple methods
url: path,
handler: mySharedHandler
})
})
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