diff --git a/src/AutoRouter.spec.ts b/src/AutoRouter.spec.ts index 2a5e37e..434a5da 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['proxy']) + }) + 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 04da2fa..9055226 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, ], diff --git a/src/types/RouterOptions.ts b/src/types/RouterOptions.ts index 981de6f..9655831 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 46f8471..70c1a63 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 951909c..31cc109 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"],