1
0

9 Commits

Author SHA1 Message Date
24a85e9814 3.2.8 2024-09-28 02:29:17 +02:00
dfdc50ba8a update dev dependencies 2024-09-28 02:29:04 +02:00
67bba2a339 3.2.7 2024-09-28 02:25:54 +02:00
c21e91bcb6 npm audit fix 2024-09-28 02:25:46 +02:00
fe2f8ec227 3.2.6 2024-09-28 02:19:32 +02:00
0e78ec4787 return cors headers for 404 response as well 2024-09-28 02:19:07 +02:00
fd7dce7256 3.2.5 2024-09-28 01:53:00 +02:00
1d72a15ca6 update readme 2024-09-28 01:51:05 +02:00
a740f1b103 audit fix 2024-07-15 22:14:32 +02:00
4 changed files with 519 additions and 737 deletions

View File

@@ -292,7 +292,7 @@ wrangler init <name>
Use of TypeScript is strongly encouraged :)
```bash
npm i -D @tsndr/cloudflare-worker-router
npm i @tsndr/cloudflare-worker-router
```

1199
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "@tsndr/cloudflare-worker-router",
"version": "3.2.4",
"version": "3.2.8",
"description": "",
"type": "module",
"exports": "./index.js",
@@ -32,9 +32,9 @@
},
"homepage": "https://github.com/tsndr/cloudflare-worker-router#readme",
"devDependencies": {
"@cloudflare/workers-types": "^4.20240222.0",
"@edge-runtime/vm": "^3.2.0",
"typescript": "^5.3.3",
"vitest": "^1.3.1"
"@cloudflare/workers-types": "^4.20240925.0",
"@edge-runtime/vm": "^4.0.3",
"typescript": "^5.6.2",
"vitest": "^2.1.1"
}
}

View File

@@ -406,34 +406,37 @@ export class Router<Env = any, CtxExt = {}, ReqExt = {}> {
}
const route = this.getRoute(req)
if (!route)
return new Response(this.debugMode ? 'Route not found!' : null, { status: 404 })
const handlers = [...this.globalHandlers, ...route.handlers]
const dbg = this.debugMode
let response: Response | undefined
for (const handler of handlers) {
const context = {
...(ctxExt ?? {}),
env,
req,
dbg,
ctx
} as RouterContext<Env, CtxExt, ReqExt>
if (!route)
response = new Response(this.debugMode ? 'Route not found!' : null, { status: 404 })
const res = await handler(context)
if (!response) {
const handlers = [
...this.globalHandlers,
...(route?.handlers ?? [])
]
if (res) {
response = res
break
for (const handler of handlers) {
const context = {
...(ctxExt ?? {}),
env,
req,
dbg: this.debugMode,
ctx
} as RouterContext<Env, CtxExt, ReqExt>
const res = await handler(context)
if (res) {
response = res
break
}
}
}
if (!response)
return new Response(this.debugMode ? 'Handler did not return a Response!' : null, { status: 404 })
response = new Response(this.debugMode ? 'Handler did not return a Response!' : null, { status: 404 })
if (this.corsEnabled) {
response = new Response(response.body, response)