Skip to content

Commit 42c05f4

Browse files
committed
Fixed prefixed routes without slash
1 parent 3ba5d3a commit 42c05f4

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

packages/event-handler/src/rest/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export const composeMiddleware = (middleware: Middleware[]): Middleware => {
205205
*/
206206
export const resolvePrefixedPath = (path: Path, prefix?: Path): Path => {
207207
if (prefix) {
208+
if (!path.startsWith('/')) return `${prefix}/${path}`;
208209
return path === '/' ? prefix : `${prefix}${path}`;
209210
}
210211
return path;

packages/event-handler/src/types/rest.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@ type RestRouteOptions = {
8080
};
8181

8282
// biome-ignore lint/suspicious/noConfusingVoidType: To ensure next function is awaited
83-
type NextFunction = () => Promise<HandlerResponse | void>;
83+
type NextFunction = () =>
84+
| Promise<HandlerResponse | void>
85+
| HandlerResponse
86+
| void;
8487

8588
type Middleware = (args: {
8689
reqCtx: RequestContext;
8790
next: NextFunction;
8891
// biome-ignore lint/suspicious/noConfusingVoidType: To ensure next function is awaited
89-
}) => Promise<HandlerResponse | void>;
92+
}) => Promise<HandlerResponse | void> | HandlerResponse | void;
9093

9194
type RouteRegistryOptions = {
9295
/**

packages/event-handler/tests/unit/rest/utils.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ describe('Path Utilities', () => {
577577
{ path: '/test', prefix: '/prefix', expected: '/prefix/test' },
578578
{ path: '/', prefix: '/prefix', expected: '/prefix' },
579579
{ path: '/test', expected: '/test' },
580+
{ path: '.+', prefix: '/prefix', expected: '/prefix/.+' },
580581
])('resolves prefixed path', ({ path, prefix, expected }) => {
581582
// Prepare & Act
582583
const resolvedPath = resolvePrefixedPath(path as Path, prefix as Path);

0 commit comments

Comments
 (0)