Skip to content

Commit

Permalink
fix: Use url pathname, instead of full url with query
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Feb 19, 2024
1 parent 585ee10 commit ca9c50b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/server/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,28 @@ export class HttpServer {
(value, key) => (req.query[key] = value)
);

const routes = this.routes[method] || [];
const routes = (this.routes[method] || []).sort(
(a, b) => b.path.toString().length - a.path.toString().length
);
for (let i = 0; i < routes.length; i++) {
const route = routes[i];
let routeExists = false;

if (route.path instanceof RegExp && route.path.test(url)) {
if (
route.path instanceof RegExp &&
route.path.test(parsedURL.pathname)
) {
routeExists = true;

// turn groups to route params
const array = Object.keys(route.path.exec(url)?.groups || {});
const array = Object.keys(
route.path.exec(parsedURL.pathname)?.groups || {}
);
for (let g = 0; g < array.length; g++) {
const key = array[g];
const value = route.path.exec(url)?.groups?.[key];
const value = route.path.exec(parsedURL.pathname)?.groups?.[
key
];

if (key == null || value == null) continue;
req.params[key] = value;
Expand Down

0 comments on commit ca9c50b

Please sign in to comment.