Skip to content

fix: middleware not returning response with new NextResponse #284

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

Merged
merged 3 commits into from
Jun 5, 2023

Conversation

james-elicx
Copy link
Contributor

This PR does the following:

  • Modifies the middleware handling to check for the x-middleware-next header and act as follows:
    • If the header exists, remove it and continue as normal.
    • If the header does not exist, and there was no rewrite or location header, this means the middleware response should be the final response we return to the client.
      • Therefore, update the final response body and status.
  • Changes the middleware error check to only be for status 500 which is what occurs when an error is thrown in a middleware func.
  • Checks if a response body was set during middleware processing and if so, bails out of routing and also uses it when returning a response to the client.
  • Adds a test for the new logic.

fixes #283

@changeset-bot
Copy link

changeset-bot bot commented May 28, 2023

🦋 Changeset detected

Latest commit: b0f3973

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/next-on-pages Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented May 28, 2023

🧪 A prerelease is available for testing 🧪

You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/runs/5176331788/npm-package-next-on-pages-284

Or you can immediately run this with npx:

npx https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/runs/5176331788/npm-package-next-on-pages-284

Copy link
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks a lot @james-elicx 😃

(sorry for the very late review 😓)

Before merging, could you please add a changeset? 🙂

@dario-piotrowicz dario-piotrowicz merged commit d91b24b into cloudflare:main Jun 5, 2023
@james-elicx james-elicx deleted the james/fix-middleware branch June 5, 2023 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Returned NextResponse from middleware is ignored
2 participants