feat: support redirect, headers, and cors route rules#538
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## main #538 +/- ##
==========================================
+ Coverage 65.34% 66.04% +0.70%
==========================================
Files 55 55
Lines 3970 4049 +79
Branches 418 437 +19
==========================================
+ Hits 2594 2674 +80
+ Misses 1372 1371 -1
Partials 4 4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
7 tasks
redirect route rulesredirect, headers, and cors route rules
atinux
approved these changes
Oct 10, 2022
redirect, headers, and cors route rulesredirect, headers, and cors route rules
pi0
reviewed
Oct 12, 2022
| 'access-control-allow-origin': '*', | ||
| 'access-control-allowed-methods': '*', | ||
| 'access-control-allow-headers': '*', | ||
| 'access-control-max-age': '0' |
Member
There was a problem hiding this comment.
We might refactor this to h3 later and support cors options (rather than a boolean). Alternatively this could be compiled into headers for better cross platform support
| for (const [key, value] of Object.entries(nitro.options.routes).filter(([_, value]) => value.redirect)) { | ||
| const redirect = typeof value.redirect === 'string' ? { to: value.redirect } : value.redirect | ||
| // TODO: update to 307 when netlify support 307/308 | ||
| contents = `${key.replace('/**', '/*')}\t${redirect.to}\t${redirect.statusCode || 301}\n` + contents |
Member
There was a problem hiding this comment.
Defaults (301 fallback) shall be done directly in nitro. For fixing 307/308 not supported, we need to check for them.
| 'access-control-allow-origin': '*', | ||
| 'access-control-allowed-methods': '*', | ||
| 'access-control-allow-headers': '*', | ||
| 'access-control-max-age': '0' |
| if (value.redirect) { | ||
| const redirect = typeof value.redirect === 'string' ? { to: value.redirect } : value.redirect | ||
| route = defu(route, { | ||
| status: redirect.statusCode || 307, |
Closed
Member
|
Thanks for this amazing PR @danielroe <3 I've added some notes, they need to be addressed before next nitropack release ~> #570 (selfassigned) |
This was referenced Oct 12, 2022
WinterYukky
pushed a commit
to WinterYukky/nitro
that referenced
this pull request
Nov 1, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
resolves #535, resolves #539, resolves #95
❓ Type of change
📚 Description
This implements redirect route rules (including platform-specific support for vercel + netlify cdns).
It also implements
headersandcorsroute rules. Apologies @pi0, I spotted too late you had self-assigned thecorsroute rule. 😬 Not my intention; happy to revert it - or feel free to amend PR.📝 Checklist