Consolidate route rewrites to netlify.toml#12
Conversation
✅ Deploy Preview for wurx-can ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Deploy Preview for wurx-otta ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| failures.push('netlify.toml must contain command = ""'); | ||
| } | ||
|
|
||
| const redirectBlocks = [...netlifyConfig.matchAll(/\[\[redirects\]\]([\s\S]*?)(?=\n\[\[redirects\]\]|$)/g)]; |
There was a problem hiding this comment.
📝 Info: Redirect block regex assumes no other TOML array sections follow [[redirects]]
The regex at line 103 (/\[\[redirects\]\]([\s\S]*?)(?=\n\[\[redirects\]\]|$)/g) captures everything from a [[redirects]] marker until the next [[redirects]] or end-of-string. For the last redirect block, the lazy quantifier consumes all remaining content to the end of the file. If other TOML array-of-tables sections (e.g. [[headers]], [[plugins]]) are ever added after the last [[redirects]] block, their content would be included in the last captured block. This doesn't cause a false positive today because the inner field matchers (from, to, status) wouldn't accidentally match unrelated TOML keys, but it's a fragility worth noting if netlify.toml grows.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if (!fromMatch || !toMatch || !statusMatch) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
📝 Info: Silently skipping malformed redirect blocks is intentional but could mask config errors
At lines 111-113, redirect blocks that are missing any of from, to, or status are silently skipped via continue. This means a partially defined redirect (e.g., missing status = 200) would not be counted as a configured rewrite, and the script would correctly report it as missing. However, it also means truly malformed blocks (e.g., typos like fron = ...) produce no specific diagnostic—the only signal is the downstream 'missing rewrite' failure, which may not clearly point to the root cause. This is acceptable for the current scope but could be improved with a warning.
Was this helpful? React with 👍 or 👎 to provide feedback.
| for (const fromPath of Object.keys(requiredRouteRewrites)) { | ||
| const escapedPath = fromPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | ||
| const duplicatePattern = new RegExp(`^\\s*${escapedPath}\\s+`, "m"); | ||
| if (duplicatePattern.test(redirectsFile)) { | ||
| failures.push(`_redirects must not duplicate rewrite for ${fromPath}; use netlify.toml only`); | ||
| } | ||
| } |
There was a problem hiding this comment.
📝 Info: _redirects duplicate detection correctly ignores comment lines
The duplicate detection pattern at line 136 (^\s*${escapedPath}\s+ with m flag) correctly avoids matching commented-out lines like # /start-a-project ... because the # character does not match the expected / at the start of the path. I verified this works correctly even with the \s* prefix (which includes \n) since ^ with the m flag anchors to line boundaries. The \s+ suffix after the path also prevents false matches against longer paths like /start-a-project-v2.
Was this helpful? React with 👍 or 👎 to provide feedback.
Motivation
netlify.tomlso routing and build settings live together.Description
_redirectsand replaced them with a short note telling maintainers to keep rewrites innetlify.toml.Rewrite configurationnote toREADME.mdstating that rewrites are maintained only innetlify.toml.scripts/check-site.jsto remove"_redirects"from the required files list, add arequiredRouteRewritesmapping, parse[[redirects]]blocks innetlify.toml, and validate required 200-status rewrites point to the correct.htmlfiles.scripts/check-site.jsthat fails if_redirectscontains duplicate rewrite entries for any required route.Testing
npm run checkwhich executesnode scripts/check-site.js, and the static site check passed.check-site.jsvalidated that all required routes are configured innetlify.tomland that_redirectsno longer duplicates those rewrites.Codex Task