Skip to content

feat: ignore trailing path segments after the parsable portion of a URL#139

Merged
jaredwray merged 4 commits into
mainfrom
claude/fix-mockhttp-137-VN1Qt
May 14, 2026
Merged

feat: ignore trailing path segments after the parsable portion of a URL#139
jaredwray merged 4 commits into
mainfrom
claude/fix-mockhttp-137-VN1Qt

Conversation

@jaredwray
Copy link
Copy Markdown
Owner

Summary

  • Adds a Fastify rewriteUrl hook in src/fastify-config.ts that, when a request URL doesn't match a specific route (only the static catch-all wildcard or nothing), progressively strips trailing path segments and rewrites to the first specific route prefix that matches.
  • Resolves Ignore everything after the parsable portion of the URL #137: /status/429/foo (or /status/429/foo/bar/) is now served by the /status/:code handler with status code 429, just like /status/429.
  • Query strings are preserved, and the first path segment is never stripped, so genuinely unknown URLs still return 404 instead of collapsing to /.
  • A wildcard catch-all match (e.g. the static-file handler at /*) is treated as "no specific match", so a stripped candidate that matches a real route wins over the wildcard. Otherwise the original URL is returned and the wildcard still serves it.

Test plan

  • pnpm test (412 tests pass, 100% line coverage; src/fastify-config.ts fully covered)
  • pnpm lint
  • pnpm build
  • New unit tests in test/fastify-config.test.ts cover: trailing segment(s), trailing slash, query string preservation, method matching, no-rewrite when URL already matches, 404 on completely unknown paths, no-strip-to-root, missing method, missing URL, and wildcard-vs-specific precedence.
  • New integration test in test/mock-http.test.ts confirms /status/429/foo returns 429 and /totally/unknown/path still returns 404 on a full MockHttp instance.

https://claude.ai/code/session_01V1j124Md6c76NjGTzHznmL


Generated by Claude Code

Adds a rewriteUrl hook that progressively strips trailing path
segments when the original URL only matches the static catch-all
wildcard or no route at all, so `/status/429/foo` is served by the
`/status/:code` handler instead of returning 404.

Fixes #137

https://claude.ai/code/session_01V1j124Md6c76NjGTzHznmL
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a URL rewriting mechanism for Fastify that allows the server to handle requests with extra trailing path segments by iteratively stripping them until a matching route is found. It includes a helper function to distinguish specific routes from wildcards and provides comprehensive unit tests. The review feedback identifies opportunities to optimize the initial route check by extracting the path from the query string earlier and suggests refining the segment-stripping loop to correctly handle edge cases like trailing slashes.

Comment thread src/fastify-config.ts Outdated
Comment thread src/fastify-config.ts Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a03f8c6) to head (0bc640f).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #139   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           37        37           
  Lines         1063      1089   +26     
  Branches       211       222   +11     
=========================================
+ Hits          1063      1089   +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…ling-slash paths

Strips the query string first so the initial findRoute check sees the
real path. Also checks the segments-as-is at the top of the loop so
URLs like `/status/429/` collapse to `/status/429` rather than `/status`.

https://claude.ai/code/session_01V1j124Md6c76NjGTzHznmL
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f82897bef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/fastify-config.ts
@jaredwray jaredwray merged commit 98cfa0a into main May 14, 2026
9 checks passed
@jaredwray jaredwray deleted the claude/fix-mockhttp-137-VN1Qt branch May 14, 2026 16:22
@jaredwray jaredwray mentioned this pull request May 16, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ignore everything after the parsable portion of the URL

2 participants