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
/**
* Environment object
* Extend request object with custom properties
*/
env: any
/**
* Context object
*/
ctx: any
/**
* Cloudflare object
*/
cf: any
extend: any
/**
* Object containing all parameters defined in the url string
*/

View File

@@ -313,19 +313,17 @@ class Router {
* @param {any} ctx
* @returns {Response}
*/
async handle(request, env, ctx) {
async handle(request, extend) {
try {
if (request instanceof Event) {
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.")
}
const req = {
...extend,
method: request.method,
headers: request.headers,
url: request.url,
env: env || {},
ctx: ctx || {},
cf: request.cf || {},
params: []
}
if (req.method === 'OPTIONS' && Object.keys(this.corsConfig).length) {

View File

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