1
0

Prepopulate request, don't parse body for DELETE method

This commit is contained in:
2022-03-23 20:48:42 +01:00
parent 2e8703d20c
commit be1d09dc93
3 changed files with 5 additions and 4 deletions

View File

@@ -152,7 +152,6 @@ Key | Type | Description
`params` | `object` | Object containing all parameters defined in the url string `params` | `object` | Object containing all parameters defined in the url string
`query` | `object` | Object containing all query parameters `query` | `object` | Object containing all query parameters
### `res`-Object ### `res`-Object
Key | Type | Description Key | Type | Description

View File

@@ -323,7 +323,9 @@ class Router {
method: request.method, method: request.method,
headers: request.headers, headers: request.headers,
url: request.url, url: request.url,
params: [] params: [],
query: {},
body: ''
} }
if (req.method === 'OPTIONS' && Object.keys(this.corsConfig).length) { if (req.method === 'OPTIONS' && Object.keys(this.corsConfig).length) {
return new Response(null, { return new Response(null, {
@@ -336,7 +338,7 @@ class Router {
status: this.corsConfig.optionsSuccessStatus status: this.corsConfig.optionsSuccessStatus
}) })
} }
if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(req.method)) { if (['POST', 'PUT', 'PATCH'].includes(req.method)) {
if (req.headers.has('Content-Type') && req.headers.get('Content-Type').includes('json')) { if (req.headers.has('Content-Type') && req.headers.get('Content-Type').includes('json')) {
try { try {
req.body = await request.json() req.body = await request.json()

View File

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