Skip to content

Commit

Permalink
Merge pull request #61 from absurdprofit/development
Browse files Browse the repository at this point in the history
Refactor resolveBaseURLFromPattern match groups filtering
  • Loading branch information
absurdprofit authored Aug 27, 2024
2 parents 1ed9a44 + e0d344e commit 6568539
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/core/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export function resolveBaseURLFromPattern(pattern: string, pathname: string) {
const baseURLMatch = new URLPattern(pattern, origin).exec(pathname, origin);
if (!baseURLMatch) return null;

const nestedPathnameGroup = baseURLMatch.pathname.groups[0] ?? '';
const groups = Object.keys(baseURLMatch.pathname.groups)
.filter((key) => !isNaN(Number(key)))
.map((key) => baseURLMatch.pathname.groups[key])
.filter((group) => group !== undefined);
const nestedPathnameGroup = groups.at(-1) ?? '';
// derive concrete baseURL
return new URL(pathname.replace(nestedPathnameGroup, ''), window.location.origin);
}
Expand Down

0 comments on commit 6568539

Please sign in to comment.