-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat: rewrite redirects sent through the proxy #139
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
feat: rewrite redirects sent through the proxy #139
Conversation
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.
Pull request overview
This PR adds support for rewriting redirect responses when proxying API requests, ensuring redirects are properly handled in both SSR and client-side contexts. The feature is controlled by a new experimental configuration option rewriteProxyRedirects (enabled by default).
Key changes:
- Implements redirect rewriting logic for proxied requests, handling relative, absolute, and same-origin redirects
- Adds configuration option to enable/disable the feature
- Includes test coverage for various redirect scenarios
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/runtime/server/proxyHandler.ts |
Core implementation of redirect rewriting logic with helper functions |
src/module.ts |
Adds configuration option and server template for the feature |
test/fixture/server/api/redirect.get.ts |
Test fixture for various redirect scenarios |
test/e2e-proxy.test.ts |
E2E tests validating redirect rewriting behavior |
src/runtime/server/handler.ts |
Adds header to track redirected responses |
playground/server/api/custom/redirect.ts |
Playground endpoint for testing redirects |
playground/server/api/custom/echo.ts |
Playground endpoint for testing requests |
playground/nuxt.config.ts |
Adds custom endpoint to playground configuration |
π‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| addTemplate({ | ||
| filename: `module/${moduleName}.config.d.ts`, | ||
| write: false, // Internal config, no need to write to disk |
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.
Turns out addTemplate forces write = true when the filename ends in .d.ts lol
|
Hey! Thanks so much for putting this PR together and thinking about edge cases in the proxy behavior. I really appreciate the effort you've put into this. π I've been thinking about the PRβ¦ and I'm questioning whether it adds enough value to justify the added complexity. Redirect rewriting for API responses is solving an uncommon edge case and inflates the scope of the module. Users who need custom redirect handling can already implement it using the existing Nitro server hooks I'd rather not bake this this behavior into into the module. If there's strong demand or compelling use cases I'm missing, I'm happy to reconsider. What do you think? |
|
I can try to reduce the scope to only allow setting |
|
I managed to implement this as a plugin. Since I'll probably make a docs PR later to add my solution as an example on how to handle redirects. |
|
Thank you! |
|
I've shared the plugin implementation as a discussion #142 |
π Linked issue
β Type of change
π Description
Rewrite redirects if for some reason an API uses them.
Also moves the config template typing to a static .d.ts file with module declarations, as it was the best way to add typing for server templates.
π Checklist