Fastify rewrite URL

I am building a public API for our system using routes, and I want to set up a URL rewrite that rewrites the URL /docs to the latest version which is sitting in a folder called v1. So for example, if someone goes to the URL https://api.authentified.co/docs (which I am using AWS API Gateway to proxy the requests through to https://platform.authentified.co/REST/) I want it to rewrite to v1/docs. I can't seem to do it with a Fastify plugin, as rewriting seems to only be available at the Factory level. https://fastify.dev/docs/latest/Reference/Server/#rewriteurl At the moment it seems like a redirect is my only option, unless there's something I've missed?
3 Replies
airhorns
airhorns2mo ago
i think you can accomplish something similar by mounting the same route function at the two different paths? you can import a route from one file and re-export it in another file to do that
Dave
DaveOP2mo ago
Oh of course Thanks @airhorns
airhorns
airhorns2mo ago
no problemo!

Did you find this page helpful?