Uh oh!
There was an error while loading. Please reload this page.
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 rulesredirect, headers, and cors route rulesredirect, headers, and cors route rulesUh oh!
There was an error while loading. Please reload this page.
| 'access-control-allow-origin': '*', | ||
| 'access-control-allowed-methods': '*', | ||
| 'access-control-allow-headers': '*', | ||
| 'access-control-max-age': '0' |
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
Uh oh!
There was an error while loading. Please reload this page.
| 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.
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, |
pi0
commented
Oct 12, 2022
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
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