Skip to content

Commit

Permalink
fix: Don’t pass response to AutoRouter missing handler (#254)
Browse files Browse the repository at this point in the history
* Don’t pass response to missing handler

* Fix typescript config and StatusError Type imports

* Fix test
  • Loading branch information
istarkov authored Aug 16, 2024
1 parent f4d79f0 commit 74e7a14
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/AutoRouter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/AutoRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand Down
2 changes: 1 addition & 1 deletion src/types/RouterOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StatusError } from 'StatusError'
import { StatusError } from '../StatusError'
import { ErrorHandler } from './ErrorHandler'
import { IRequest } from './IRequest'
import { IttyRouterOptions } from './IttyRouterOptions'
Expand Down
2 changes: 1 addition & 1 deletion src/types/RouterType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StatusError } from 'StatusError'
import { StatusError } from '../StatusError'
import { ErrorHandler } from './ErrorHandler'
import { IRequest } from './IRequest'
import { IttyRouterType } from './IttyRouterType'
Expand Down
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"declaration": true,
"sourceMap": true,
"esModuleInterop": true,
Expand All @@ -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"],
Expand Down

0 comments on commit 74e7a14

Please sign in to comment.