Skip to content

Commit

Permalink
released v5.0.7 - withParams has more explicit check to prevent bindi…
Browse files Browse the repository at this point in the history
…ng null
  • Loading branch information
kwhitley committed Apr 2, 2024
1 parent ddc41f9 commit 6c6afc1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Changelog

- **v5.0.7**
- fixed: withParams could attempt to bind null (collision with node adapter)
- **v5.0.6**
- fixed: corsify as replacing status codes (now mutates original response)
- **v5.0.5**
Expand Down
42 changes: 42 additions & 0 deletions examples/runtimes/node-autorouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const { error } = require("../../dist/index")
const { AutoRouter } = require("../../dist/AutoRouter")
const { createServerAdapter } = require("@whatwg-node/server")
const http = require("http")

const router = AutoRouter({
catch: (err) => {
console.log('ERROR', err.message, err.stack)

return error(500, err.stack)
}
})

router.get('*', () => "Hello itty-router v5")

const serverAdapter = createServerAdapter(async (request) => {
// this works

const url = new URL(request.url)

console.log({
url: request.url,
newURL: url,
method: request.method,
})

request.query = {}
request.params = {}
request.route = '/foo'
request.proxy = new Proxy(request, {})

const slimRequest = {
method: request.method,
url: request.url,
}

return await router.fetch(request)
})

const httpServer = http.createServer(serverAdapter)

httpServer.listen(5000)
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.6",
"version": "5.0.7",
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",
"main": "./index.js",
"module": "./index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default async () => {
],
plugins: [
typescript({ sourceMap: true }),
terser(),
// terser(),
bundleSize(),
copy({
targets: [
Expand Down
2 changes: 1 addition & 1 deletion src/withParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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[prop]?.bind?.(request) || obj[prop]
: obj?.params?.[prop]
})
}

0 comments on commit 6c6afc1

Please sign in to comment.