From 206d5002d6fea76d71ba8fd81f55c6e1b3ef9aca Mon Sep 17 00:00:00 2001 From: Christian Svensson Date: Mon, 16 Oct 2023 07:45:34 +0200 Subject: [PATCH] fix: add error-handler type to manifest (#1933) --- deno.json | 3 ++- src/server/context.ts | 2 +- src/server/mod.ts | 11 ++++++++--- tests/fixture_custom_500/routes/_500.tsx | 6 +++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/deno.json b/deno.json index c187ffb2..44b8c0a2 100644 --- a/deno.json +++ b/deno.json @@ -6,7 +6,8 @@ "www": "deno task --cwd=www start", "screenshot": "deno run -A www/utils/screenshot.ts", "check:types": "deno check **/*.ts && deno check **/*.tsx", - "ok": "deno fmt --check && deno lint && deno task check:types && deno task test" + "ok": "deno fmt --check && deno lint && deno task check:types && deno task test", + "install-puppeteer": "PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@16.2.0/install.ts && PUPPETEER_PRODUCT=firefox deno run -A --unstable https://deno.land/x/puppeteer@16.2.0/install.ts" }, "exclude": [ "**/_fresh/*", diff --git a/src/server/context.ts b/src/server/context.ts index 25206b5b..27eb3ff4 100644 --- a/src/server/context.ts +++ b/src/server/context.ts @@ -172,7 +172,7 @@ export async function getServerContext(opts: InternalFreshConfig) { if (!url.startsWith(baseUrl + "routes")) { throw new TypeError("Page is not a child of the basepath."); } - const path = url.substring(baseUrl.length).substring("routes".length); + const path = url.substring(baseUrl.length + "routes".length); const baseRoute = path.substring(1, path.length - extname(path).length); const name = baseRoute.replace("/", "-"); const isLayout = path.endsWith("/_layout.tsx") || diff --git a/src/server/mod.ts b/src/server/mod.ts index 642a48a1..9dbee912 100644 --- a/src/server/mod.ts +++ b/src/server/mod.ts @@ -74,9 +74,14 @@ export interface Manifest { ctx: any, // deno-lint-ignore no-explicit-any ) => Promise | any; - // deno-lint-ignore no-explicit-any - handler?: Handler | Handlers | UnknownHandler; - config?: RouteConfig | LayoutConfig | ErrorHandler; + handler?: + // deno-lint-ignore no-explicit-any + | Handler + // deno-lint-ignore no-explicit-any + | Handlers + | UnknownHandler + | ErrorHandler; + config?: RouteConfig | LayoutConfig; } | MiddlewareModule >; islands: Record; diff --git a/tests/fixture_custom_500/routes/_500.tsx b/tests/fixture_custom_500/routes/_500.tsx index 06ec8219..fb2fd55b 100644 --- a/tests/fixture_custom_500/routes/_500.tsx +++ b/tests/fixture_custom_500/routes/_500.tsx @@ -1,4 +1,8 @@ -import { ErrorPageProps } from "../../../server.ts"; +import { ErrorHandler, ErrorPageProps } from "../../../server.ts"; + +export const handler: ErrorHandler = (_req, ctx) => { + return ctx.render(); +}; export default function Error500Page({ error }: ErrorPageProps) { return

Custom 500: {(error as Error).message}

;