Skip to content

Commit 844776f

Browse files
committed
fix(addRoute): always normalize path and method
1 parent 5a1bb1b commit 844776f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/operations/add.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ export function addRoute<T>(
1111
path: string,
1212
data?: T,
1313
): void {
14+
method = method.toUpperCase();
15+
if (path[0] !== "/") {
16+
path = `/${path}`;
17+
}
18+
1419
const segments = splitPath(path);
1520

1621
let node = ctx.root;
@@ -72,10 +77,8 @@ export function addRoute<T>(
7277
if (!node.methods) {
7378
node.methods = new NullProtoObj();
7479
}
75-
if (!node.methods![method]) {
76-
node.methods![method] = [];
77-
}
78-
node.methods![method].push({
80+
node.methods![method] ??= [];
81+
node.methods![method]!.push({
7982
data: data || (null as T),
8083
paramsMap: hasParams ? paramsMap : undefined,
8184
});

0 commit comments

Comments
 (0)