Skip to content

Conversation

@mattmess1221
Copy link
Contributor

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSDoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Rewrite redirects if for some reason an API uses them.

  • Absolute and same-origin locations will be rewritten.
    • Locations to outside the endpoint's URL path are unsupported and will cause a Server Error.
  • Relative and cross-origin locations will not be rewritten.

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

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link
Contributor

Copilot AI left a 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
Copy link
Contributor Author

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

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.

1 participant