From 46cd8b9eb4c5e9b526a6cba288070630b8dcbbf5 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Wed, 11 May 2022 15:07:40 -0600 Subject: [PATCH] Fix APIRoute type (#3344) * Fix APIRoute type * Adds a changeset * Update usage of the two API route signatures --- .changeset/curly-bees-collect.md | 5 +++++ packages/astro/src/@types/astro.ts | 12 ++---------- packages/astro/src/runtime/server/index.ts | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) create mode 100644 .changeset/curly-bees-collect.md diff --git a/.changeset/curly-bees-collect.md b/.changeset/curly-bees-collect.md new file mode 100644 index 0000000000..982fa253d6 --- /dev/null +++ b/.changeset/curly-bees-collect.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix for APIRoute type diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index e57126180b..050223b53f 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -883,18 +883,10 @@ export interface EndpointOutput { body: Output; } -interface APIRoute { - (context: APIContext): EndpointOutput | Response; - - /** - * @deprecated - * Use { context: APIRouteContext } object instead. - */ - (params: Params, request: Request): EndpointOutput | Response; -} +export type APIRoute = (context: APIContext) => EndpointOutput | Response; export interface EndpointHandler { - [method: string]: APIRoute; + [method: string]: APIRoute | ((params: Params, request: Request) => EndpointOutput | Response); } export interface AstroRenderer { diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 13d408f978..9a46cb9c73 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -517,7 +517,7 @@ Update your code to remove this warning.`); }, }) as APIContext & Params; - return await handler.call(mod, proxy, request); + return handler.call(mod, proxy, request); } async function replaceHeadInjection(result: SSRResult, html: string): Promise {