diff --git a/CHANGELOG.md b/CHANGELOG.md index 572c33d1..4d5bff92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Changelog +- **v4.0.27** + - fixed: .toUpperCase issue that prevented serialization of entire router - **v4.0.24** - fixed: createResponse(undefined) should return undefined (not a Response) - **v4.1.0** diff --git a/package.json b/package.json index cc32da77..3b385d30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "itty-router", - "version": "4.0.26", + "version": "4.0.27", "description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.", "main": "./index.js", "module": "./index.mjs", diff --git a/src/Router.spec.ts b/src/Router.spec.ts index 64d735be..7f18c70c 100644 --- a/src/Router.spec.ts +++ b/src/Router.spec.ts @@ -51,6 +51,12 @@ describe('Router', () => { expect(router.routes.length).toBe(3) // accessible off the main router }) + it('can serialize router without throwing', () => { + const router = Router().get('/', () => 'foo') + + expect(() => console.log(router)).not.toThrow() + }) + it('router.handle (legacy) is an alias for router.fetch (new)', () => { expect(router.fetch).toBe(router.handle) }) diff --git a/src/Router.ts b/src/Router.ts index a84933d1..ac97b7fc 100644 --- a/src/Router.ts +++ b/src/Router.ts @@ -88,7 +88,7 @@ export const Router = < (route: string, ...handlers: RouteHandler[]) => routes.push( [ - prop.toUpperCase(), + prop.toUpperCase?.(), RegExp(`^${(path = (base + route) .replace(/\/+(\/|$)/g, '$1')) // strip double & trailing splash .replace(/(\/?\.?):(\w+)\+/g, '($1(?<$2>*))') // greedy params