I’m proxying requests to an external backend from a Nextjs app and trying to extract an
Authorization
header from the response using the native fetch library. However the headers in the fetch response are empty even though they are present in the actual response from the server.
Here’s the setup in the next.config.js
file:
module.exports = {
async headers() {
return [
{
source: '/api/:path*',
headers: [
{
key: 'Access-Control-Expose-Headers',
value: '*, authorization',
},
],
},
]
},
async rewrites() {
return [
{
source: '/api/:path*',
destination: `${process.env.NEXT_PUBLIC_BASE_URL}/api/:path*`,
},
]
},
}
With my limited knowledge of proxies I’m assuming that it’s a reverse proxy and the headers are lost in the response back somewhere inside it.
I’ve also tried adding a middleware to try to localize where the headers are being lost without any luck.
Does anyone know where I can configure the headers to be included back from the proxy?
Thanks in advance! 🙂