Skip to content

Commit 97ce735

Browse files
fix: server routes handle per verb middlewares
fixes #4490
1 parent 5b94b9d commit 97ce735

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

packages/start-server-core/src/createStartHandler.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,26 @@ async function handleServerRoutes(opts: {
375375

376376
if (method) {
377377
const handler = serverTreeResult.foundRoute.options.methods[method]
378-
379378
if (handler) {
380-
middlewares.push(handlerToMiddleware(handler) as TODO)
379+
if (typeof handler === 'function') {
380+
middlewares.push(handlerToMiddleware(handler) as TODO)
381+
} else {
382+
if (
383+
handler._options.middlewares &&
384+
handler._options.middlewares.length
385+
) {
386+
middlewares.push(
387+
...flattenMiddlewares(handler._options.middlewares as any).map(
388+
(d) => d.options.server,
389+
),
390+
)
391+
}
392+
if (handler._options.handler) {
393+
middlewares.push(
394+
handlerToMiddleware(handler._options.handler),
395+
)
396+
}
397+
}
381398
}
382399
}
383400
}

packages/start-server-core/src/serverRoute.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,22 @@ export interface ServerRouteOptions<
4545
middleware?: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>
4646
methods?: Record<
4747
string,
48-
ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, any, any>
48+
| ServerRouteMethodHandlerFn<
49+
TParentRoute,
50+
TFullPath,
51+
TMiddlewares,
52+
any,
53+
any
54+
>
55+
| {
56+
_options: ServerRouteMethodBuilderOptions<
57+
TParentRoute,
58+
TFullPath,
59+
TMiddlewares,
60+
unknown,
61+
unknown
62+
>
63+
}
4964
>
5065
caseSensitive?: boolean
5166
}

0 commit comments

Comments
 (0)