Skip to content

Commit

Permalink
released v5.0.11 - code-golfing
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhitley committed Apr 9, 2024
1 parent e0ecf73 commit 3c688e2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "itty-router",
"version": "5.0.10",
"version": "5.0.11",
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",
"main": "./index.js",
"module": "./index.mjs",
Expand Down
6 changes: 2 additions & 4 deletions src/websocket.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { createResponse } from './createResponse'

export const websocket = (client: WebSocket, options: object = {}) =>
createResponse()(null, {
export const websocket = (client: WebSocket, options?: ResponseInit) =>
new Response(null, {
status: 101,
webSocket: client,
...options,
Expand Down
9 changes: 5 additions & 4 deletions src/withParams.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { IRequest } from './types'

export const withParams = (request: IRequest): void => {
request.proxy = new Proxy(request.proxy || request, {
get: (obj, prop) => obj[prop] !== undefined
? obj[prop]?.bind?.(request) || obj[prop]
: obj?.params?.[prop]
request.proxy = new Proxy(request.proxy ?? request, {
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
})
}

0 comments on commit 3c688e2

Please sign in to comment.