@cfworker/web
Advanced tools
Comparing version 1.8.0 to 1.8.1
@@ -7,2 +7,3 @@ export * from './accepts.js'; | ||
export * from './middleware.js'; | ||
export * from './normalize-pathname.js'; | ||
export * from './req.js'; | ||
@@ -9,0 +10,0 @@ export * from './response-builder.js'; |
@@ -7,2 +7,3 @@ export * from './accepts.js'; | ||
export * from './middleware.js'; | ||
export * from './normalize-pathname.js'; | ||
export * from './req.js'; | ||
@@ -9,0 +10,0 @@ export * from './response-builder.js'; |
import { safeParse } from 'secure-json-parse'; | ||
import { Accepts } from './accepts.js'; | ||
import { HttpError } from './http-error.js'; | ||
export class Req { | ||
@@ -9,13 +8,2 @@ constructor(request) { | ||
this.url = new URL(request.url); | ||
try { | ||
this.url.pathname = decodeURIComponent(this.url.pathname) | ||
.replace(/\/\/+/g, '/') | ||
.normalize(); | ||
} | ||
catch (err) { | ||
if (err instanceof URIError) { | ||
throw new HttpError(400, `Unable to decode pathname "${this.url.pathname}".`); | ||
} | ||
throw err; | ||
} | ||
this.headers = request.headers; | ||
@@ -22,0 +10,0 @@ this.params = Object.create(null); |
{ | ||
"name": "@cfworker/web", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"description": "Web framework for Cloudflare Workers and service workers, inspired by Koa and fastify", | ||
@@ -12,2 +12,3 @@ "keywords": [ | ||
], | ||
"sideEffects": false, | ||
"main": "dist/index.js", | ||
@@ -37,3 +38,3 @@ "module": "dist/index.js", | ||
"dependencies": { | ||
"@cfworker/json-schema": "^1.8.0", | ||
"@cfworker/json-schema": "^1.8.1", | ||
"@cfworker/worker-types": "^1.8.0", | ||
@@ -64,3 +65,3 @@ "@cloudflare/workers-types": "^2.1.0", | ||
}, | ||
"gitHead": "f338fb849e8eb8c0a355680c595a079d0107807e" | ||
"gitHead": "04a6d9e39173ffdfd3067b91be55be1d69abd409" | ||
} |
@@ -12,3 +12,9 @@ # @cfworker/web | ||
```ts | ||
import { Application, Middleware, Router, validate } from '@cfworker/web'; | ||
import { | ||
Application, | ||
Middleware, | ||
Router, | ||
validate, | ||
normalizePathnameMiddleware | ||
} from '@cfworker/web'; | ||
@@ -72,3 +78,7 @@ const router = new Router(); | ||
// Compose the application | ||
new Application().use(cors).use(router.middleware).listen(); | ||
new Application() | ||
.use(normalizePathnameMiddleware) | ||
.use(cors) | ||
.use(router.middleware) | ||
.listen(); | ||
``` | ||
@@ -75,0 +85,0 @@ |
@@ -7,2 +7,3 @@ export * from './accepts.js'; | ||
export * from './middleware.js'; | ||
export * from './normalize-pathname.js'; | ||
export * from './req.js'; | ||
@@ -9,0 +10,0 @@ export * from './response-builder.js'; |
import { Reviver, safeParse } from 'secure-json-parse'; | ||
import { Accepts } from './accepts.js'; | ||
import { HttpError } from './http-error.js'; | ||
@@ -18,15 +17,2 @@ export class Req { | ||
this.url = new URL(request.url); | ||
try { | ||
this.url.pathname = decodeURIComponent(this.url.pathname) | ||
.replace(/\/\/+/g, '/') | ||
.normalize(); | ||
} catch (err) { | ||
if (err instanceof URIError) { | ||
throw new HttpError( | ||
400, | ||
`Unable to decode pathname "${this.url.pathname}".` | ||
); | ||
} | ||
throw err; | ||
} | ||
this.headers = request.headers; | ||
@@ -33,0 +19,0 @@ this.params = Object.create(null); |
51682
43
1435
92
+ Added@types/node@22.13.1(transitive)
- Removed@types/node@22.13.0(transitive)
Updated@cfworker/json-schema@^1.8.1