1
0

18 Commits

Author SHA1 Message Date
8f400ff5b7 3.0.0-6 2023-02-02 18:38:37 +01:00
51f30f642f clean up 2023-02-02 18:37:45 +01:00
bcab122e15 add dbg to handler context 2023-02-02 18:37:28 +01:00
f3181ca9a5 change || to ?? 2023-02-02 18:31:33 +01:00
7edfc835fa change interfaces to types 2023-02-02 18:30:03 +01:00
7300e36469 update migration guide 2023-02-02 18:08:49 +01:00
e122feadb5 update readmes 2023-02-02 17:40:28 +01:00
ceed474f24 3.0.0-5 2023-01-16 21:27:11 +01:00
864b7f153c extend request type 2023-01-16 21:26:42 +01:00
6a2173cdbc 3.0.0-4 2022-11-28 23:09:34 +01:00
87a3d344d9 add req.raw type 2022-11-28 23:09:12 +01:00
9f96fd112e 3.0.0-3 2022-11-28 23:04:30 +01:00
5f34e30c1e add raw request 2022-11-28 23:04:12 +01:00
b38baf7d62 add editorconfig 2022-11-28 23:03:59 +01:00
07cb83ff9f 3.0.0-2 2022-11-28 21:27:49 +01:00
2a064dcb9c make cf ctx optional 2022-11-28 21:27:25 +01:00
5e18d06dfd 3.0.0-1 2022-11-28 20:34:54 +01:00
4f169120de update workflow 2022-11-28 20:33:18 +01:00
7 changed files with 134 additions and 125 deletions

View File

@@ -1,4 +1,4 @@
name: Publish (main) name: Publish (pre)
on: on:
release: release:
@@ -20,11 +20,11 @@ jobs:
- name: Publish to npmjs - name: Publish to npmjs
env: env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: npm publish --tag latest --access public run: npm publish --tag pre --access public
- uses: actions/setup-node@v1 - uses: actions/setup-node@v1
with: with:
registry-url: https://npm.pkg.github.com/ registry-url: https://npm.pkg.github.com/
- name: Publish to GPR - name: Publish to GPR
env: env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: npm publish --tag latest --access public run: npm publish --tag pre --access public

View File

@@ -4,3 +4,4 @@ test/
.nvmrc .nvmrc
MIGRATION.md MIGRATION.md
tsconfig.json tsconfig.json
.editorconfig

View File

@@ -1,71 +1,70 @@
# Migration Guide # Migration Guide
From `v1.x.x` to `v2.x.x`. From `v2.x.x` to `v3.x.x`.
## Contents ## Contents
- [Preparation](#preparation) - [Update Router](#update-router)
- [Update](#update) - [Handlers](#handlers)
- [Import / Require](#import--require)
- [Routes](#routes)
- [Fetch](#fetch--routerhandle) - [Fetch](#fetch--routerhandle)
## Preparation ## Update Router
Follow Cloudflare's [Migration Guide](https://developers.cloudflare.com/workers/wrangler/migration/migrating-from-wrangler-1/) to update your protject to [wrangler2](https://github.com/cloudflare/wrangler2). Update to the latest version version of the router.
## Update
Update to the latest version verstion
```bash ```bash
npm i -D @tsndr/cloudflare-worker-router npm i -D @tsndr/cloudflare-worker-router
``` ```
## Import / Require
Switch to ESModules. ## Handlers
- Remove `res` and `next` from handler parameter list.
- Replace `res.` with `return new Response()` / `return Response.json()`.
- Remove `next()` calls from middlewares.
### Before ### Before
```javascript ```typescript
const Router = require('@tsndr/cloudflare-worker-router') // Register global middleware
router.use(({ env, req, res, next }) => {
if (req.headers.get('authorization') !== env.SECRET_TOKEN) {
res.status = 401
return
}
next()
})
// Simple get
router.get('/user', ({ res }) => {
res.body = {
id: 1,
name: 'John Doe'
}
})
``` ```
### After ### After
```javascript ```typescript
import Router from '@tsndr/cloudflare-worker-router' // Register global middleware
router.use(({ env, req }) => {
// Intercept if token doesn't match
if (req.headers.get('authorization') !== env.SECRET_TOKEN) {
return new Response(null, { status: 401 })
}
})
// Simple get
router.get('/user', () => {
return Response.json({
id: 1,
name: 'John Doe'
})
})
``` ```
## Routes
Just add curly braces.
### Before
<a href="https://gist.github.com/tsndr/34e8544266ae15d51abd019d7c3d27ca" target="_blank"><img width="469" alt="Petrify 2022-06-24 at 5 57 01 PM" src="https://user-images.githubusercontent.com/2940127/175572731-a8729c1b-15e2-45ac-be80-7e8527c5502a.png"></a>
### After
<a href="https://gist.github.com/tsndr/8db6e8dd55e348015c2ff8e93dd6aa31" target="_blank"><img width="469" alt="Petrify 2022-06-24 at 5 55 56 PM" src="https://user-images.githubusercontent.com/2940127/175572549-0eea8fc4-3d90-412a-89cc-d2f4569f1139.png"></a>
## Fetch / `router.handle()`
❗️ Be aware that with `v2.0.0` the parameters of `router.handle()` changed ❗️
### Before
<a href="https://gist.github.com/tsndr/12b0f800269760c597646c90a562ef88" target="_blank"><img width="469" alt="Petrify 2022-06-24 at 5 58 43 PM" src="https://user-images.githubusercontent.com/2940127/175572993-fb4681c2-eece-4c92-88e8-1c2f57644769.png"></a>
### After
<a href="https://gist.github.com/tsndr/30902b01b134e2a58cf3a53648dd3e47" target="_blank"><img width="393" alt="Petrify 2022-06-24 at 5 59 22 PM" src="https://user-images.githubusercontent.com/2940127/175573110-b7dfcfb2-855d-4529-a957-6f8b9ec439f3.png"></a>

View File

@@ -26,6 +26,8 @@ I worked a lot with [Express.js](https://expressjs.com/) in the past and really
## Usage ## Usage
Migrating from `v2.x.x`, check out the [Migration Guide](MIGRATION.md).
### TypeScript Example ### TypeScript Example
```typescript ```typescript
@@ -51,12 +53,10 @@ const router = new Router<Env>()
router.cors() router.cors()
// Register global middleware // Register global middleware
router.use(() => { router.use(({ env, req }) => {
return new Response(null, { // Intercept if token doesn't match
headers: { if (req.headers.get('authorization') !== env.SECRET_TOKEN)
'X-Global-Middlewares': 'true' return new Response(null, { status: 401 })
}
})
}) })
// Simple get // Simple get
@@ -85,9 +85,7 @@ router.post('/user/:id', ({ req }) => {
// Delete route using a middleware // Delete route using a middleware
router.delete('/user/:id', ({ env, req }) => { router.delete('/user/:id', ({ env, req }) => {
const { SECRET_TOKEN } = env if (req.headers.get('authorization') === env.SECRET_TOKEN)
if (req.headers.get('Authorization') === SECRET_TOKEN)
return new Response(null, { status: 401 }) return new Response(null, { status: 401 })
}, ({ req }) => { }, ({ req }) => {
@@ -121,12 +119,10 @@ const router = new Router()
router.cors() router.cors()
// Register global middleware // Register global middleware
router.use(() => { router.use(({ env, req }) => {
return new Response(null, { // Intercept if token doesn't match
headers: { if (req.headers.get('authorization') !== env.SECRET_TOKEN)
'X-Global-Middlewares': 'true' return new Response(null, { status: 401 })
}
})
}) })
// Simple get // Simple get
@@ -139,11 +135,12 @@ router.get('/user', () => {
// Post route with url parameter // Post route with url parameter
router.post('/user/:id', ({ req }) => { router.post('/user/:id', ({ req }) => {
const userId = req.params.id const userId = req.params.id
// Do stuff // Do stuff
if (errorDoingStuff) { if (!true) {
return Response.json({ return Response.json({
error: 'Error doing stuff!' error: 'Error doing stuff!'
}, { status: 400 }) }, { status: 400 })
@@ -154,12 +151,11 @@ router.post('/user/:id', ({ req }) => {
// Delete route using a middleware // Delete route using a middleware
router.delete('/user/:id', ({ env, req }) => { router.delete('/user/:id', ({ env, req }) => {
const { SECRET_TOKEN } = env if (req.headers.get('authorization') === env.SECRET_TOKEN)
if (req.headers.get('Authorization') === SECRET_TOKEN)
return new Response(null, { status: 401 }) return new Response(null, { status: 401 })
}, ({ req }) => { }, ({ req }) => {
const userId = req.params.id const userId = req.params.id
// Do stuff... // Do stuff...
@@ -306,15 +302,15 @@ const router = new Router<Env>()
/// Example Route /// Example Route
// //
// router.get(/'hi', ({ res }) => { // router.get(/'hi', async () => {
// res.body = 'Hello World' // return new Response('Hello World')
//} //}
/// Example Route for splitting into multiple files /// Example Route for splitting into multiple files
// //
// const hiHandler: RouteHandler<Env> = ({ res }) => { // const hiHandler: RouteHandler<Env> = async () => {
// res.body = 'Hello World' // return new Response('Hello World')
// } // }
// //
// router.get('/hi', hiHandler) // router.get('/hi', hiHandler)
@@ -340,10 +336,20 @@ import { Router } from '@tsndr/cloudflare-worker-router'
const router = new Router() const router = new Router()
// router.get(/'hi', ({ res }) => { /// Example Route
// res.body = 'Hello World' //
// router.get(/'hi', async () => {
// return new Response('Hello World')
//} //}
/// Example Route for splitting into multiple files
//
// async function hiHandler() {
// return new Response('Hello World')
// }
//
// router.get('/hi', hiHandler)
// TODO: add your routes here // TODO: add your routes here
export default { export default {

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "@tsndr/cloudflare-worker-router", "name": "@tsndr/cloudflare-worker-router",
"version": "3.0.0-0", "version": "3.0.0-6",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@tsndr/cloudflare-worker-router", "name": "@tsndr/cloudflare-worker-router",
"version": "3.0.0-0", "version": "3.0.0-6",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@cloudflare/workers-types": "^3.13.0", "@cloudflare/workers-types": "^3.13.0",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@tsndr/cloudflare-worker-router", "name": "@tsndr/cloudflare-worker-router",
"version": "3.0.0-0", "version": "3.0.0-6",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"types": "index.d.ts", "types": "index.d.ts",

View File

@@ -6,10 +6,10 @@
* @property {string} url URL String * @property {string} url URL String
* @property {RouterHandler[]} handlers Array of handler functions * @property {RouterHandler[]} handlers Array of handler functions
*/ */
export interface Route<TEnv> { export type Route<TEnv, TExt> = {
method: string method: string
url: string url: string
handlers: RouterHandler<TEnv>[] handlers: RouterHandler<TEnv, TExt>[]
} }
/** /**
@@ -20,10 +20,11 @@ export interface Route<TEnv> {
* @property {RouterRequest} req Request Object * @property {RouterRequest} req Request Object
* @property {ExecutionContext} ctx Context Object * @property {ExecutionContext} ctx Context Object
*/ */
export interface RouterContext<TEnv = any> { export type RouterContext<TEnv = any, TExt = any> = {
env: TEnv env: TEnv
req: RouterRequest req: RouterRequest<TExt>
ctx: ExecutionContext dbg: boolean
ctx?: ExecutionContext
} }
/** /**
@@ -38,23 +39,23 @@ export interface RouterContext<TEnv = any> {
* @property {string | any} body Only available if method is `POST`, `PUT`, `PATCH` or `DELETE`. Contains either the received body string or a parsed object if valid JSON was sent. * @property {string | any} body Only available if method is `POST`, `PUT`, `PATCH` or `DELETE`. Contains either the received body string or a parsed object if valid JSON was sent.
* @property {IncomingRequestCfProperties} [cf] object containing custom Cloudflare properties. (https://developers.cloudflare.com/workers/examples/accessing-the-cloudflare-object) * @property {IncomingRequestCfProperties} [cf] object containing custom Cloudflare properties. (https://developers.cloudflare.com/workers/examples/accessing-the-cloudflare-object)
*/ */
export interface RouterRequest { export type RouterRequest<TExt> = {
url: string url: string
method: string method: string
params: RouterRequestParams params: RouterRequestParams
query: RouterRequestQuery query: RouterRequestQuery
headers: Headers headers: Headers
body: string | any body: string | any
raw: Request
cf?: IncomingRequestCfProperties cf?: IncomingRequestCfProperties
[key: string]: any } & TExt
}
/** /**
* Request Parameters * Request Parameters
* *
* @typedef RouterRequestParams * @typedef RouterRequestParams
*/ */
export interface RouterRequestParams { export type RouterRequestParams = {
[key: string]: string [key: string]: string
} }
@@ -63,7 +64,7 @@ export interface RouterRequestParams {
* *
* @typedef RouterRequestQuery * @typedef RouterRequestQuery
*/ */
export interface RouterRequestQuery { export type RouterRequestQuery = {
[key: string]: string [key: string]: string
} }
@@ -74,8 +75,8 @@ export interface RouterRequestQuery {
* @param {RouterContext} ctx * @param {RouterContext} ctx
* @returns {Promise<Response | void> Response | void} * @returns {Promise<Response | void> Response | void}
*/ */
export interface RouterHandler<TEnv = any> { export type RouterHandler<TEnv = any, TExt = any> = {
(ctx: RouterContext<TEnv>): Promise<Response | void> | Response | void (ctx: RouterContext<TEnv, TExt>): Promise<Response | void> | Response | void
} }
/** /**
@@ -88,7 +89,7 @@ export interface RouterHandler<TEnv = any> {
* @property {number} [maxAge=86400] Access-Control-Max-Age (default: `86400`) * @property {number} [maxAge=86400] Access-Control-Max-Age (default: `86400`)
* @property {number} [optionsSuccessStatus=204] Return status code for OPTIONS request (default: `204`) * @property {number} [optionsSuccessStatus=204] Return status code for OPTIONS request (default: `204`)
*/ */
export interface RouterCorsConfig { export type RouterCorsConfig = {
allowOrigin?: string allowOrigin?: string
allowMethods?: string allowMethods?: string
allowHeaders?: string allowHeaders?: string
@@ -102,7 +103,7 @@ export interface RouterCorsConfig {
* @public * @public
* @class * @class
*/ */
export class Router<TEnv = any> { export class Router<TEnv = any, TExt = any> {
/** /**
* Router Array * Router Array
@@ -110,7 +111,7 @@ export class Router<TEnv = any> {
* @protected * @protected
* @type {Route[]} * @type {Route[]}
*/ */
protected routes: Route<TEnv>[] = [] protected routes: Route<TEnv, TExt>[] = []
/** /**
* Global Handlers * Global Handlers
@@ -118,7 +119,7 @@ export class Router<TEnv = any> {
* @protected * @protected
* @type {RouterHandler[]} * @type {RouterHandler[]}
*/ */
protected globalHandlers: RouterHandler<TEnv>[] = [] protected globalHandlers: RouterHandler<TEnv, TExt>[] = []
/** /**
* Debug Mode * Debug Mode
@@ -150,7 +151,7 @@ export class Router<TEnv = any> {
* @param {RouterHandler[]} handlers * @param {RouterHandler[]} handlers
* @returns {Router} * @returns {Router}
*/ */
public use(...handlers: RouterHandler<TEnv>[]): Router<TEnv> { public use(...handlers: RouterHandler<TEnv, TExt>[]): Router<TEnv, TExt> {
for (let handler of handlers) { for (let handler of handlers) {
this.globalHandlers.push(handler) this.globalHandlers.push(handler)
} }
@@ -164,7 +165,7 @@ export class Router<TEnv = any> {
* @param {RouterHandler[]} handlers * @param {RouterHandler[]} handlers
* @returns {Router} * @returns {Router}
*/ */
public connect(url: string, ...handlers: RouterHandler<TEnv>[]): Router<TEnv> { public connect(url: string, ...handlers: RouterHandler<TEnv, TExt>[]): Router<TEnv, TExt> {
return this.register('CONNECT', url, handlers) return this.register('CONNECT', url, handlers)
} }
@@ -175,7 +176,7 @@ export class Router<TEnv = any> {
* @param {RouterHandler[]} handlers * @param {RouterHandler[]} handlers
* @returns {Router} * @returns {Router}
*/ */
public delete(url: string, ...handlers: RouterHandler<TEnv>[]): Router<TEnv> { public delete(url: string, ...handlers: RouterHandler<TEnv, TExt>[]): Router<TEnv, TExt> {
return this.register('DELETE', url, handlers) return this.register('DELETE', url, handlers)
} }
@@ -186,7 +187,7 @@ export class Router<TEnv = any> {
* @param {RouterHandler[]} handlers * @param {RouterHandler[]} handlers
* @returns {Router} * @returns {Router}
*/ */
public get(url: string, ...handlers: RouterHandler<TEnv>[]): Router<TEnv> { public get(url: string, ...handlers: RouterHandler<TEnv, TExt>[]): Router<TEnv, TExt> {
return this.register('GET', url, handlers) return this.register('GET', url, handlers)
} }
@@ -197,7 +198,7 @@ export class Router<TEnv = any> {
* @param {RouterHandler[]} handlers * @param {RouterHandler[]} handlers
* @returns {Router} * @returns {Router}
*/ */
public head(url: string, ...handlers: RouterHandler<TEnv>[]): Router<TEnv> { public head(url: string, ...handlers: RouterHandler<TEnv, TExt>[]): Router<TEnv, TExt> {
return this.register('HEAD', url, handlers) return this.register('HEAD', url, handlers)
} }
@@ -208,7 +209,7 @@ export class Router<TEnv = any> {
* @param {RouterHandler[]} handlers * @param {RouterHandler[]} handlers
* @returns {Router} * @returns {Router}
*/ */
public options(url: string, ...handlers: RouterHandler<TEnv>[]): Router<TEnv> { public options(url: string, ...handlers: RouterHandler<TEnv, TExt>[]): Router<TEnv, TExt> {
return this.register('OPTIONS', url, handlers) return this.register('OPTIONS', url, handlers)
} }
@@ -219,7 +220,7 @@ export class Router<TEnv = any> {
* @param {RouterHandler[]} handlers * @param {RouterHandler[]} handlers
* @returns {Router} * @returns {Router}
*/ */
public patch(url: string, ...handlers: RouterHandler<TEnv>[]): Router<TEnv> { public patch(url: string, ...handlers: RouterHandler<TEnv, TExt>[]): Router<TEnv, TExt> {
return this.register('PATCH', url, handlers) return this.register('PATCH', url, handlers)
} }
@@ -230,7 +231,7 @@ export class Router<TEnv = any> {
* @param {RouterHandler[]} handlers * @param {RouterHandler[]} handlers
* @returns {Router} * @returns {Router}
*/ */
public post(url: string, ...handlers: RouterHandler<TEnv>[]): Router<TEnv> { public post(url: string, ...handlers: RouterHandler<TEnv, TExt>[]): Router<TEnv, TExt> {
return this.register('POST', url, handlers) return this.register('POST', url, handlers)
} }
@@ -241,7 +242,7 @@ export class Router<TEnv = any> {
* @param {RouterHandler[]} handlers * @param {RouterHandler[]} handlers
* @returns {Router} * @returns {Router}
*/ */
public put(url: string, ...handlers: RouterHandler<TEnv>[]): Router<TEnv> { public put(url: string, ...handlers: RouterHandler<TEnv, TExt>[]): Router<TEnv, TExt> {
return this.register('PUT', url, handlers) return this.register('PUT', url, handlers)
} }
@@ -252,7 +253,7 @@ export class Router<TEnv = any> {
* @param {RouterHandler[]} handlers * @param {RouterHandler[]} handlers
* @returns {Router} * @returns {Router}
*/ */
public trace(url: string, ...handlers: RouterHandler<TEnv>[]): Router<TEnv> { public trace(url: string, ...handlers: RouterHandler<TEnv, TExt>[]): Router<TEnv, TExt> {
return this.register('TRACE', url, handlers) return this.register('TRACE', url, handlers)
} }
@@ -263,7 +264,7 @@ export class Router<TEnv = any> {
* @param {RouterHandler[]} handlers * @param {RouterHandler[]} handlers
* @returns {Router} * @returns {Router}
*/ */
public any(url: string, ...handlers: RouterHandler<TEnv>[]): Router<TEnv> { public any(url: string, ...handlers: RouterHandler<TEnv, TExt>[]): Router<TEnv, TExt> {
return this.register('*', url, handlers) return this.register('*', url, handlers)
} }
@@ -273,7 +274,7 @@ export class Router<TEnv = any> {
* @param {boolean} [state=true] Whether to turn on or off debug mode (default: true) * @param {boolean} [state=true] Whether to turn on or off debug mode (default: true)
* @returns {Router} * @returns {Router}
*/ */
public debug(state: boolean = true): Router<TEnv> { public debug(state: boolean = true): Router<TEnv, TExt> {
this.debugMode = state this.debugMode = state
return this return this
} }
@@ -284,14 +285,14 @@ export class Router<TEnv = any> {
* @param {RouterCorsConfig} [config] * @param {RouterCorsConfig} [config]
* @returns {Router} * @returns {Router}
*/ */
public cors(config?: RouterCorsConfig): Router<TEnv> { public cors(config?: RouterCorsConfig): Router<TEnv, TExt> {
this.corsEnabled = true this.corsEnabled = true
this.corsConfig = { this.corsConfig = {
allowOrigin: config?.allowOrigin || '*', allowOrigin: config?.allowOrigin ?? '*',
allowMethods: config?.allowMethods || '*', allowMethods: config?.allowMethods ?? '*',
allowHeaders: config?.allowHeaders || '*', allowHeaders: config?.allowHeaders ?? '*',
maxAge: config?.maxAge || 86400, maxAge: config?.maxAge ?? 86400,
optionsSuccessStatus: config?.optionsSuccessStatus || 204 optionsSuccessStatus: config?.optionsSuccessStatus ?? 204
} }
return this return this
} }
@@ -317,7 +318,7 @@ export class Router<TEnv = any> {
* @param {RouterHandler[]} handlers Arrar of handler functions * @param {RouterHandler[]} handlers Arrar of handler functions
* @returns {Router} * @returns {Router}
*/ */
private register(method: string, url: string, handlers: RouterHandler<TEnv>[]): Router<TEnv> { private register(method: string, url: string, handlers: RouterHandler<TEnv, TExt>[]): Router<TEnv, TExt> {
this.routes.push({ this.routes.push({
method, method,
url, url,
@@ -334,7 +335,7 @@ export class Router<TEnv = any> {
* @param {RouterRequest} request * @param {RouterRequest} request
* @returns {Route | undefined} * @returns {Route | undefined}
*/ */
private getRoute(request: RouterRequest): Route<TEnv> | undefined { private getRoute(request: RouterRequest<TExt>): Route<TEnv, TExt> | undefined {
const url = new URL(request.url) const url = new URL(request.url)
const pathArr = url.pathname.split('/').filter(i => i) const pathArr = url.pathname.split('/').filter(i => i)
@@ -371,22 +372,23 @@ export class Router<TEnv = any> {
/** /**
* Handle requests * Handle requests
* *
* @param {TEnv} env
* @param {Request} request * @param {Request} request
* @param {any} [extend] * @param {TEnv} env
* @param {TExt} [ext]
* @returns {Promise<Response>} * @returns {Promise<Response>}
*/ */
public async handle(request: Request, env: TEnv, ctx: ExecutionContext, extend: any = {}): Promise<Response> { public async handle(request: Request, env: TEnv, ctx?: ExecutionContext, ext?: TExt): Promise<Response> {
const req: RouterRequest = { const req = {
...extend, ...(ext ?? {}),
method: request.method, method: request.method,
headers: request.headers, headers: request.headers,
url: request.url, url: request.url,
cf: request.cf, cf: request.cf,
raw: request,
params: {}, params: {},
query: {}, query: {},
body: '' body: ''
} } as RouterRequest<TExt>
const route = this.getRoute(req) const route = this.getRoute(req)
@@ -401,11 +403,12 @@ export class Router<TEnv = any> {
} }
const handlers = [...this.globalHandlers, ...route.handlers] const handlers = [...this.globalHandlers, ...route.handlers]
const dbg = this.debugMode
let response: Response | undefined let response: Response | undefined
for (const handler of handlers) { for (const handler of handlers) {
const res = await handler({ env, req, ctx }) const res = await handler({ env, req, dbg, ctx })
if (res) { if (res) {
response = res response = res