Skip to content

[backport v1.3.x] fix(router): only strip basePath when it is a leading prefix#152

Merged
bytaesu merged 1 commit into
v1.3.xfrom
backport-149-to-v1.3.x
Jun 24, 2026
Merged

[backport v1.3.x] fix(router): only strip basePath when it is a leading prefix#152
bytaesu merged 1 commit into
v1.3.xfrom
backport-149-to-v1.3.x

Conversation

@better-release

Copy link
Copy Markdown

Description

Backport of #149 to v1.3.x.

* fix(router): only strip basePath when it is a leading prefix

The router derived the route path by stripping basePath wherever it
appeared via pathname.split(basePath), which dropped any segments before
the first occurrence. A pathname like /x/api/test would then resolve onto
the internal route /test even though it is not mounted under basePath.

Strip basePath only when it is a leading, /-boundary prefix of the request
pathname; pathnames outside basePath now resolve to a 404. Trailing slashes
on basePath are normalized so /api/auth/ and /api/auth behave the same.

* refactor(router): derive base path once and flatten path resolution

Compute the trailing-slash-normalized base path once at router creation
instead of on every request, and resolve the request path with guard-clause
early returns. Behavior is unchanged. Add a regression test for a sibling
prefix that matches without a "/" boundary.

---------

Co-authored-by: Taesu <bytaesu@gmail.com>
(cherry picked from commit de59505)
@pkg-pr-new

pkg-pr-new Bot commented Jun 24, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/better-call@152

commit: 51134ff

@bytaesu bytaesu merged commit a3c0b4a into v1.3.x Jun 24, 2026
5 checks passed
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.

2 participants