Compare commits
9 Commits
v3.2.5
...
7bb935fa53
| Author | SHA1 | Date | |
|---|---|---|---|
|
7bb935fa53
|
|||
|
49d5806d89
|
|||
|
73a0d4a4f9
|
|||
|
24a85e9814
|
|||
|
dfdc50ba8a
|
|||
|
67bba2a339
|
|||
|
c21e91bcb6
|
|||
|
fe2f8ec227
|
|||
|
0e78ec4787
|
@@ -15,6 +15,8 @@ jobs:
|
|||||||
registry-url: https://registry.npmjs.org/
|
registry-url: https://registry.npmjs.org/
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
- name: Run tests
|
||||||
|
run: npm test
|
||||||
- name: Build
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
- name: Publish to npmjs
|
- name: Publish to npmjs
|
||||||
953
package-lock.json
generated
953
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tsndr/cloudflare-worker-router",
|
"name": "@tsndr/cloudflare-worker-router",
|
||||||
"version": "3.2.5",
|
"version": "3.2.9",
|
||||||
"description": "",
|
"description": "",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": "./index.js",
|
"exports": "./index.js",
|
||||||
@@ -32,9 +32,9 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/tsndr/cloudflare-worker-router#readme",
|
"homepage": "https://github.com/tsndr/cloudflare-worker-router#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^4.20240222.0",
|
"@cloudflare/workers-types": "^4.20241022.0",
|
||||||
"@edge-runtime/vm": "^3.2.0",
|
"@edge-runtime/vm": "^4.0.3",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.6.3",
|
||||||
"vitest": "^1.3.1"
|
"vitest": "^2.1.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
43
src/index.ts
43
src/index.ts
@@ -406,34 +406,37 @@ export class Router<Env = any, CtxExt = {}, ReqExt = {}> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const route = this.getRoute(req)
|
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
|
let response: Response | undefined
|
||||||
|
|
||||||
for (const handler of handlers) {
|
if (!route)
|
||||||
const context = {
|
response = new Response(this.debugMode ? 'Route not found!' : null, { status: 404 })
|
||||||
...(ctxExt ?? {}),
|
|
||||||
env,
|
|
||||||
req,
|
|
||||||
dbg,
|
|
||||||
ctx
|
|
||||||
} as RouterContext<Env, CtxExt, ReqExt>
|
|
||||||
|
|
||||||
const res = await handler(context)
|
if (!response) {
|
||||||
|
const handlers = [
|
||||||
|
...this.globalHandlers,
|
||||||
|
...(route?.handlers ?? [])
|
||||||
|
]
|
||||||
|
|
||||||
if (res) {
|
for (const handler of handlers) {
|
||||||
response = res
|
const context = {
|
||||||
break
|
...(ctxExt ?? {}),
|
||||||
|
env,
|
||||||
|
req,
|
||||||
|
dbg: this.debugMode,
|
||||||
|
ctx
|
||||||
|
} as RouterContext<Env, CtxExt, ReqExt>
|
||||||
|
|
||||||
|
const res = await handler(context)
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
response = res
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response)
|
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) {
|
if (this.corsEnabled) {
|
||||||
response = new Response(response.body, response)
|
response = new Response(response.body, response)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": ".",
|
"outDir": ".",
|
||||||
"module": "commonjs",
|
"module": "esnext",
|
||||||
"target": "esnext",
|
"target": "esnext",
|
||||||
"lib": ["esnext"],
|
"lib": ["esnext"],
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user