-
Notifications
You must be signed in to change notification settings - Fork 544
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: support redirect
, headers
, and cors
route rules
#538
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. |
redirect
route rulesredirect
, headers
, and cors
route rules
redirect
, headers
, and cors
route rulesredirect
, headers
, and cors
route rules
'access-control-allow-origin': '*', | ||
'access-control-allowed-methods': '*', | ||
'access-control-allow-headers': '*', | ||
'access-control-max-age': '0' |
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.
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 |
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.
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' |
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.
(related to cors refactor)
if (value.redirect) { | ||
const redirect = typeof value.redirect === 'string' ? { to: value.redirect } : value.redirect | ||
route = defu(route, { | ||
status: redirect.statusCode || 307, |
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.
Defaults to be moved into nitro
Thanks for this amazing PR @danielroe <3 I've added some notes, they need to be addressed before next nitropack release ~> #570 (selfassigned) |
π 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
headers
andcors
route rules. Apologies @pi0, I spotted too late you had self-assigned thecors
route rule. π¬ Not my intention; happy to revert it - or feel free to amend PR.π Checklist