-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Response headers not accessible on api routes in Vercel #40275
Comments
I seem to have encountered the same issue. When updating headers in export default async function middleware(request: NextRequest) {
return rewrite(request.nextUrl, {
headers: {
"test": "please",
}
})
};
export const config = {
matcher: '/api/:path*',
runtime: 'experimental-edge',
}; In any import type { NextApiRequest, NextApiResponse } from 'next'
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
res.getHeader('test') // doesn't exists
} |
I am running into a similar issue... I update the headers in
but when I try to access it from the API, the value is
This is only happening when the app is deployed to Vercel. I am able to access the updated response headers just fine locally. |
Possibly duplicate of #49442 - have a look at the workaround we have there. |
I have the same issue. When calling |
Verify canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #202207312230
166078056622.04~9d60db1 SMP PREEMPT_DYNAMIC Thu ABinaries:
Node: 16.15.0
npm: 8.5.5
Yarn: 1.22.18
pnpm: N/A
Relevant packages:
next: 12.2.5
eslint-config-next: 12.1.0
react: 17.0.2
react-dom: 17.0.2
What browser are you using? (if relevant)
Chrome
How are you deploying your application? (if relevant)
Vercel, Netlify
Describe the Bug
Trying to access response headers on pages/api routes not working in production on Vercel. On my
middleware.ts
I set some cookie like:response.cookies.set('userId', 'blah')
and on my
next.config.js
I set headers like:Now when I try to log the headers on pages/api/someroute like:
Locally In Development and Production:
In Vercel:
[Object: null prototype] {}
Why are headers not accessible on api routes in Vercel?
Expected Behavior
When I set headers in response on middleware like indicated here
https://nextjs.org/docs/advanced-features/middleware#using-cookies
I should be able to access them in routes when deployed to Vercel according to docs https://nextjs.org/docs/api-routes/response-helpers and https://nodejs.org/api/http.html#http_class_http_serverresponse
Link to reproduction
N/A
To Reproduce
The text was updated successfully, but these errors were encountered: