From 420ec07658ec2f1ab7437b1e7d47f13100d9752c Mon Sep 17 00:00:00 2001 From: istarkov Date: Sat, 6 Jul 2024 08:06:59 +0300 Subject: [PATCH 1/3] =?UTF-8?q?Don=E2=80=99t=20pass=20response=20to=20miss?= =?UTF-8?q?ing=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AutoRouter.spec.ts | 8 ++++++++ src/AutoRouter.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/AutoRouter.spec.ts b/src/AutoRouter.spec.ts index 2a5e37ec..1a81a555 100644 --- a/src/AutoRouter.spec.ts +++ b/src/AutoRouter.spec.ts @@ -55,6 +55,14 @@ describe(`SPECIFIC TESTS: AutoRouter`, () => { expect(response.status).toBe(418) }) + it('missing: RouteHandler - receives request as the first parameter', async () => { + const missing = vi.fn(() => {}) + const router = AutoRouter({ missing }) + const request = toReq('/') + await router.fetch(request) + expect(missing).toBeCalledWith(request) + }) + it('before: RouteHandler - adds upstream middleware', async () => { const handler = vi.fn(r => typeof r.date) const router = AutoRouter({ diff --git a/src/AutoRouter.ts b/src/AutoRouter.ts index 04da2fa6..90552263 100644 --- a/src/AutoRouter.ts +++ b/src/AutoRouter.ts @@ -24,7 +24,7 @@ export const AutoRouter = < catch: error, finally: [ // @ts-ignore - (r: any, ...args) => r ?? missing(r, ...args), + (r: any, ...args) => r ?? missing(...args), format, ...f, ], From 7cb145879aa831f4bee1465d4b7995f659eae07f Mon Sep 17 00:00:00 2001 From: istarkov Date: Sun, 7 Jul 2024 12:40:57 +0300 Subject: [PATCH 2/3] Fix typescript config and StatusError Type imports --- src/types/RouterOptions.ts | 2 +- src/types/RouterType.ts | 2 +- tsconfig.json | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/types/RouterOptions.ts b/src/types/RouterOptions.ts index 981de6f1..96558314 100644 --- a/src/types/RouterOptions.ts +++ b/src/types/RouterOptions.ts @@ -1,4 +1,4 @@ -import { StatusError } from 'StatusError' +import { StatusError } from '../StatusError' import { ErrorHandler } from './ErrorHandler' import { IRequest } from './IRequest' import { IttyRouterOptions } from './IttyRouterOptions' diff --git a/src/types/RouterType.ts b/src/types/RouterType.ts index 46f84717..70c1a63f 100644 --- a/src/types/RouterType.ts +++ b/src/types/RouterType.ts @@ -1,4 +1,4 @@ -import { StatusError } from 'StatusError' +import { StatusError } from '../StatusError' import { ErrorHandler } from './ErrorHandler' import { IRequest } from './IRequest' import { IttyRouterType } from './IttyRouterType' diff --git a/tsconfig.json b/tsconfig.json index 951909ca..31cc109c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,6 @@ "compilerOptions": { "allowJs": true, "allowSyntheticDefaultImports": true, - "baseUrl": "src", "declaration": true, "sourceMap": true, "esModuleInterop": true, @@ -12,15 +11,13 @@ "listFiles": false, "noFallthroughCasesInSwitch": true, "pretty": true, - // "moduleResolution": "nodeNext", // disabled to be compatible with module: "esnext" - // "resolveJsonModule": true, // disabled to be compatible with module: "esnext" "rootDir": "src", "skipLibCheck": true, "strict": true, "traceResolution": false, "outDir": "", "target": "esnext", - "module": "esnext", + "module": "Preserve", "types": ["@cloudflare/workers-types", "@types/node"] }, "exclude": ["node_modules", "dist", "**/*.spec.ts", "examples"], From f181730cad6b3fd9d15c7fafcb4b8b7a396f1ab2 Mon Sep 17 00:00:00 2001 From: istarkov Date: Wed, 10 Jul 2024 22:59:06 +0300 Subject: [PATCH 3/3] Fix test --- src/AutoRouter.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AutoRouter.spec.ts b/src/AutoRouter.spec.ts index 1a81a555..434a5dac 100644 --- a/src/AutoRouter.spec.ts +++ b/src/AutoRouter.spec.ts @@ -60,7 +60,7 @@ describe(`SPECIFIC TESTS: AutoRouter`, () => { const router = AutoRouter({ missing }) const request = toReq('/') await router.fetch(request) - expect(missing).toBeCalledWith(request) + expect(missing).toBeCalledWith(request['proxy']) }) it('before: RouteHandler - adds upstream middleware', async () => {