1
0

Change router.handle(request, env, ctx) to router.handle(request, extend)

This commit is contained in:
2022-03-18 20:03:29 +01:00
parent 61a02ca9db
commit f7a236f1f2
3 changed files with 5 additions and 15 deletions

12
index.d.ts vendored
View File

@@ -288,17 +288,9 @@ type RouterRequest = {
*/ */
url: string url: string
/** /**
* Environment object * Extend request object with custom properties
*/ */
env: any extend: any
/**
* Context object
*/
ctx: any
/**
* Cloudflare object
*/
cf: any
/** /**
* Object containing all parameters defined in the url string * Object containing all parameters defined in the url string
*/ */

View File

@@ -313,19 +313,17 @@ class Router {
* @param {any} ctx * @param {any} ctx
* @returns {Response} * @returns {Response}
*/ */
async handle(request, env, ctx) { async handle(request, extend) {
try { try {
if (request instanceof Event) { if (request instanceof Event) {
request = request.request request = request.request
console.warn("Warning: Using `event` on `router.handle()` is deprecated and might go away in future versions, please use `event.request` instead.") console.warn("Warning: Using `event` on `router.handle()` is deprecated and might go away in future versions, please use `event.request` instead.")
} }
const req = { const req = {
...extend,
method: request.method, method: request.method,
headers: request.headers, headers: request.headers,
url: request.url, url: request.url,
env: env || {},
ctx: ctx || {},
cf: request.cf || {},
params: [] params: []
} }
if (req.method === 'OPTIONS' && Object.keys(this.corsConfig).length) { if (req.method === 'OPTIONS' && Object.keys(this.corsConfig).length) {

View File

@@ -1,6 +1,6 @@
{ {
"name": "@tsndr/cloudflare-worker-router", "name": "@tsndr/cloudflare-worker-router",
"version": "1.2.0", "version": "1.2.1",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": {}, "scripts": {},