Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhitley committed Apr 9, 2024
1 parent 9d6aac0 commit 19a43e7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/withParams.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('withParams (middleware)', () => {
it('allows accessing route params from the request itself', async () => {
const router = Router()
const handler = vi.fn(({ id, method }) => ({ id, method }))
const request = { method: 'GET', url: 'https://foo.bar/baz' }
const request = toReq('/baz')

await router.get('/:id', withParams, handler).fetch(request)

Expand Down Expand Up @@ -37,7 +37,7 @@ describe('withParams (middleware)', () => {
it('can be used as global upstream middleware', async () => {
const router = Router()
const handler = vi.fn(({ id, method }) => ({ id, method }))
const request = { method: 'GET', url: 'https://foo.bar/baz' }
const request = toReq('/baz')

await router.all('*', withParams).get('/:id', handler).fetch(request)

Expand Down
2 changes: 1 addition & 1 deletion src/withParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IRequest } from './types'

export const withParams = (request: IRequest): void => {
request.proxy = new Proxy(request.proxy ?? request, {
get: (obj, prop, receiver) =>
get: (obj, prop) =>
obj[prop]?.bind?.(request) // if prop exists (as function), return the function, bound to the original request
?? obj[prop] // if prop exists, return it
?? obj?.params?.[prop] // if no prop exists, try the params object
Expand Down

0 comments on commit 19a43e7

Please sign in to comment.