-
Notifications
You must be signed in to change notification settings - Fork 29.3k
Closed
Labels
MiddlewareRelated to Next.js Middleware.Related to Next.js Middleware.bugIssue was opened via the bug report template.Issue was opened via the bug report template.
Description
Verify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 20.6.0: Wed Nov 10 22:23:07 PST 2021; root:xnu-7195.141.14~1/RELEASE_X86_64
Binaries:
Node: 14.19.0
npm: 6.14.16
Yarn: 1.22.15
pnpm: N/A
Relevant packages:
next: 12.1.0
react: 17.0.2
react-dom: 17.0.2
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
vercel
Describe the Bug
The below example will return a valid response when deployed to Vercel.
But when running locally you will get [object Object]
.
You may want to convert a response into a NextResponse
in order to mutate headers, and access builtin NextResponse
methods like nextUrl
or .cookie()
.
async function middleware() {
const response = await fetch('https://www.vercel.com');
const clonedResponse = new NextResponse(response.body, response);
return clonedResponse;
}
Just using native Response
works in both environments.
async function middleware() {
const response = await fetch('https://www.vercel.com');
const clonedResponse = new Response(response.body, response);
return clonedResponse;
}
Expected Behavior
I should be able to convert a Response
into a NextResponse
in both local dev AND when deployed to vercel.
To Reproduce
See code snippet above.
Metadata
Metadata
Assignees
Labels
MiddlewareRelated to Next.js Middleware.Related to Next.js Middleware.bugIssue was opened via the bug report template.Issue was opened via the bug report template.