Skip to content

fix: pass x-middleware-rewrite header to client #1322

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 2 commits into from
Apr 25, 2022

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Apr 22, 2022

Summary

Currently our middleware edge function wrapper strips any internal Next headers before returning them to the client. This is a mistake, because Next uses these headers during navigation. This PR adds them back in.

Test plan

  1. Visit the middleware deploy preview, https://deploy-preview-1322--next-plugin-edge-middleware.netlify.app/
  2. Click the Rewrite me link on the homepage
  3. Ensure it's rewritten to a show the page at https://deploy-preview-1322--next-plugin-edge-middleware.netlify.app/shows/100

CleanShot 2022-04-22 at 13 12 56

Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal

Fixes #1321

capybara and anteater

Standard checks:

  • Check the Deploy Preview's Demo site for your PR's functionality
  • Add docs when necessary

🧪 Once merged, make sure to update the version if needed and that it was published correctly.

@netlify
Copy link

netlify bot commented Apr 22, 2022

Deploy Preview for netlify-plugin-nextjs-demo ready!

Name Link
🔨 Latest commit 4cfb9d7
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/62629aa30940ba000919b1fc
😎 Deploy Preview https://deploy-preview-1322--netlify-plugin-nextjs-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Apr 22, 2022
@netlify
Copy link

netlify bot commented Apr 22, 2022

Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!

Name Link
🔨 Latest commit 4cfb9d7
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/62629aa3e72b17000912eac2
😎 Deploy Preview https://deploy-preview-1322--netlify-plugin-nextjs-nx-monorepo-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Apr 22, 2022

Deploy Preview for next-plugin-rsc-demo canceled.

Name Link
🔨 Latest commit 4cfb9d7
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-rsc-demo/deploys/62629aa3f8b3870008d7bf77

@netlify
Copy link

netlify bot commented Apr 22, 2022

Deploy Preview for next-plugin-edge-middleware ready!

Name Link
🔨 Latest commit 4cfb9d7
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/62629aa34cb040000826e08b
😎 Deploy Preview https://deploy-preview-1322--next-plugin-edge-middleware.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Apr 22, 2022

Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!

Name Link
🔨 Latest commit 4cfb9d7
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/62629aa3c865fd000826d4cc
😎 Deploy Preview https://deploy-preview-1322--netlify-plugin-nextjs-static-root-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Apr 22, 2022

Deploy Preview for netlify-plugin-nextjs-export-demo ready!

Name Link
🔨 Latest commit 4cfb9d7
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/62629aa319ec65000833a87f
😎 Deploy Preview https://deploy-preview-1322--netlify-plugin-nextjs-export-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@cypress
Copy link

cypress bot commented Apr 22, 2022



Test summary

22 0 0 0


Run details

Project netlify-plugin-nextjs-default-demo
Status Passed
Commit bd8bcb3 ℹ️
Started Apr 22, 2022 12:11 PM
Ended Apr 22, 2022 12:12 PM
Duration 01:21 💡
OS Linux Ubuntu - 20.04
Browser Chrome 100

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@cypress
Copy link

cypress bot commented Apr 22, 2022



Test summary

7 0 0 0


Run details

Project netlify-plugin-nextjs-static-demo
Status Passed
Commit bd8bcb3 ℹ️
Started Apr 22, 2022 12:12 PM
Ended Apr 22, 2022 12:13 PM
Duration 01:12 💡
OS Linux Ubuntu - 20.04
Browser Chrome 100

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@cypress
Copy link

cypress bot commented Apr 22, 2022



Test summary

2 0 0 0


Run details

Project netlify-plugin-nextjs-nx-monorepo-demo
Status Passed
Commit bd8bcb3 ℹ️
Started Apr 22, 2022 12:12 PM
Ended Apr 22, 2022 12:14 PM
Duration 01:11 💡
OS Linux Ubuntu - 20.04
Browser Chrome 100

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@ascorbic ascorbic marked this pull request as ready for review April 22, 2022 13:11
@ascorbic ascorbic requested a review from a team April 22, 2022 13:11
@@ -33,11 +33,9 @@ export const buildResponse = async ({
request.headers.set('x-nf-next-middleware', 'skip')
const rewrite = res.headers.get('x-middleware-rewrite')
if (rewrite) {
res.headers.delete('x-middleware-rewrite')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the bit that matters

Copy link

@nickytonline nickytonline left a comment

Choose a reason for hiding this comment

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

Tested it out and works as expected. 🚀

@kodiakhq kodiakhq bot merged commit ed17658 into main Apr 25, 2022
@kodiakhq kodiakhq bot deleted the mk/middleware-rewrite-header branch April 25, 2022 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Edge Functions Beta - Middleware rewrites not working as expected
2 participants