Alter headers and rewrite to external URL in middleware
Unanswered
Alligator mississippiensis posted this in #help-forum
Alligator mississippiensisOP
Hi.
I'm using Next.js for the frontend of my application and have an API in the backend that's completely separate (for increased performance and flexibility). I'm trying to proxy requests to my API through Next.js middleware. For example, given the API endpoints
I'd appreciate any help you guys can give me 🙂
I'm using Next.js for the frontend of my application and have an API in the backend that's completely separate (for increased performance and flexibility). I'm trying to proxy requests to my API through Next.js middleware. For example, given the API endpoints
https://api.mybackend.com/example-endpoint and https://my-nextjs-app.com/api/example-endpoint, I rewrite the Next.js endpoint (which doesn't actually exist) to the actual endpoint. This is working as expected. However, I'm also attempting to alter the request headers during the Next.js middleware execution. My backend receives the original request headers, but it doesn't receive the altered headers. Has anyone else experienced this? I've read through a few issues on Github that describe something similar, but they're from a few years ago and didn't include a solution.I'd appreciate any help you guys can give me 🙂