fix(seo): move noindex logic from middleware.ts into proxy.ts#44
fix(seo): move noindex logic from middleware.ts into proxy.ts#44JohnRDOrazio merged 2 commits intomainfrom
Conversation
Next.js 16 deprecated middleware.ts in favor of proxy.ts. The repo already had proxy.ts (using next-intl/middleware for locale routing), and PR #42 unknowingly added middleware.ts alongside it. Next.js refuses to build with both files: Error: Both middleware file "./middleware.ts" and proxy file "./proxy.ts" are detected. Please use "./proxy.ts" only. Production deploy run 25180664827 failed at build with this error. Fix: - Delete middleware.ts. - Fold the host-allowlist + X-Robots-Tag logic into proxy.ts as a composed proxy() function: it runs next-intl middleware on the routes intl owns (existing exclusion regex), passes through otherwise, then sets X-Robots-Tag: noindex, nofollow on any non-production host. - Broaden the matcher from the previous intl-only exclusion to '/((?!_next/static|_next/image).*)' so the noindex header also reaches /api/*, /robots.txt, and /sitemap*.xml on staging. Locale routing is gated by an in-function regex check so the broader matcher doesn't change intl behavior. Verified locally: npm run build completes; route summary shows "ƒ Proxy (Middleware)" indicating the proxy is wired in. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe removed Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 10 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@proxy.ts`:
- Around line 52-58: The INTL_EXCLUDE regex used in proxy() is too permissive
and excludes paths that merely start with those names (e.g., /apiary); tighten
it by requiring a segment boundary or exact filename: update the INTL_EXCLUDE
pattern so each literal (api, _next, wp-admin, wp-login, wp-json, graphql,
wp-content, favicon.ico, logo.svg) is matched only if followed by end-of-string
or a slash (or in the case of filenames, end-of-string), e.g. use grouping with
(?:$|/) or explicit filename anchors; keep the proxy() flow using that
INTL_EXCLUDE and still call intlProxy(request) when it does not match.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a169253d-ffee-4439-9587-120889b2252a
📒 Files selected for processing (2)
middleware.tsproxy.ts
💤 Files with no reviewable changes (1)
- middleware.ts
CodeRabbit caught a soundness bug in the regex: literals like `api`, `_next`, `wp-json`, `graphql` matched anything starting with those strings, so paths like `/apiary`, `/_nextish`, `/wp-jsonary`, `/graphqlbang` were wrongly excluded from next-intl routing. Tightened so each path-segment literal must be followed by `/` or end-of-string, and filename literals (`favicon.ico`, `logo.svg`) must anchor to end. The trailing `.*\..*` keeps catching asset-like paths containing a dot. Smoke-tested 26 cases including all the suffix-attack paths, genuinely-excluded paths, and intl-eligible paths. All pass. \`npm run build\` still succeeds locally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
Hotfix. Next.js 16 deprecated
middleware.tsin favor ofproxy.ts. The repo already hadproxy.ts(using next-intl forlocale routing); PR #42 unknowingly added
middleware.tsalongsideit, and Next.js refuses to build with both:
Production deploy run 25180664827
failed at build with this error after PRs #42 + #43 merged.
Fix
middleware.tsproxy.tsas a customproxy()function:
exclusion regex
/(api|_next|wp-admin|wp-login|wp-json|graphql|wp-content|favicon.ico|logo.svg|.*\..*))X-Robots-Tag: noindex, nofollowon any non-productionhost (allowlist derived from
NEXT_PUBLIC_SITE_URLwith safefallback, same logic as before)
/((?!_next/static|_next/image).*)so the noindex header reaches/api/*,/robots.txt, and/sitemap*.xmlon staging too.Locale routing is gated by an in-function regex check so the
broader matcher doesn't change intl behavior.
Test plan
npm run buildclean locally; route summary showsƒ Proxy (Middleware)confirming proxy is wiredconfirm build succeeds and deploys
curl -I https://catholicdigitalcommons.org/→ noX-Robots-Tagcurl -I https://staging.catholicdigitalcommons.org/api/sitemap→
X-Robots-Tag: noindex, nofollow🤖 Generated with Claude Code
Summary by CodeRabbit