Skip to content

Commit 46cd8b9

Browse files
authored
Fix APIRoute type (#3344)
* Fix APIRoute type * Adds a changeset * Update usage of the two API route signatures
1 parent 1a5335e commit 46cd8b9

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

.changeset/curly-bees-collect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fix for APIRoute type

packages/astro/src/@types/astro.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -883,18 +883,10 @@ export interface EndpointOutput<Output extends Body = Body> {
883883
body: Output;
884884
}
885885

886-
interface APIRoute {
887-
(context: APIContext): EndpointOutput | Response;
888-
889-
/**
890-
* @deprecated
891-
* Use { context: APIRouteContext } object instead.
892-
*/
893-
(params: Params, request: Request): EndpointOutput | Response;
894-
}
886+
export type APIRoute = (context: APIContext) => EndpointOutput | Response;
895887

896888
export interface EndpointHandler {
897-
[method: string]: APIRoute;
889+
[method: string]: APIRoute | ((params: Params, request: Request) => EndpointOutput | Response);
898890
}
899891

900892
export interface AstroRenderer {

packages/astro/src/runtime/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ Update your code to remove this warning.`);
517517
},
518518
}) as APIContext & Params;
519519

520-
return await handler.call(mod, proxy, request);
520+
return handler.call(mod, proxy, request);
521521
}
522522

523523
async function replaceHeadInjection(result: SSRResult, html: string): Promise<string> {

0 commit comments

Comments
 (0)