-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Remove Edge Functions example that writes to the response body #261
Conversation
@SukkaW is attempting to deploy a commit to the Vercel Solutions Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
10 Ignored Deployments
|
Hi @SukkaW, thanks for realizing that this weren't relevant anymore with the last update, its really useful! I will talk with the team to see if we can keep any of them doing changes like a redirect or a rewrite but most seem safe to delete. Will let you know soon and thanks again 🙌 |
Indeed, thanks for the hard work @SukkaW! |
@goncy Thanks for your review! IMHO these examples shouldn't exist in the first place: those are pages' middleware (and pages should be rendered in the browser) and it doesn't make sense to let a page's middleware return a JSON. However, the API route of Next.js should be able to switch to the edge function runtime instead. I will raise a Feature Request toward Next.js. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SukkaW Hi there and thank you for the PR 👋
We don't want to remove any examples yet, instead we want to update them to use redirects/rewrites, even if that doesn't make a lot of sense, for the case of crypto,
image-response, and
json-response` lets update the readme and link to the new API where we take the decision and reasoning behind it. The examples have been existing for a while now and removing them breaks shared links.
Sounds fair. |
Closing this PR in favor of multiple PRs the team has been making to update the examples in a different way, thank you for the work you did here! |
Description
Ref: vercel/next.js#36835
Since Next.js
v12.1.7-canary.10
, Next.js page middleware removes the support of modifying the response body, and here I quote:And here are reasons why those examples should be removed:
edge-functions/cors
The example uses
new Response(null, { statusCode: 204 })
to respond a CORS preflight request (AnOPTIONS
request) inside a "page middleware" which is now unsupported.edge-functions/json-response and edge-functions/crypto
In these two examples' middlewares, they write a
JSON.stringify
-ed to a returned response body inside the "page middleware" which is now unsupported.edge-functions/image-response
In this example's middleware, it writes a blob (containing an image binary) to a returned response body inside a "page middleware" which is now unsupported.
Also, there are still two examples that write to the response body in the middleware, which I will change in the coming PR:
edge-functions/basic-auth-password
In this example's middleware, it writes
Auth required
to the returned 401 response. I will change it toNextResponse.rewrite('/auth-required')
in the coming PR.edge-functions/geo-location-country-block
I will change it to
NextResponse.rewrite
in the coming PR.Also cc @ijjk @feugy
Best Way to Test
N/A
Type of Change
New Example Checklist
README.md
preview link in PR description (branch)npm run new-example
was run to create the example