From f020fa732b2f8b75370177999160f3f6e45765a3 Mon Sep 17 00:00:00 2001 From: ganbin Date: Tue, 24 Jun 2025 16:31:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=8C=96=E8=AF=B7=E6=B1=82=E4=BC=AA=E8=A3=85=E4=BB=A5=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E4=B8=8D=E6=94=AF=E6=8C=81=20PUT/DELETE=20=E7=9A=84?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/manager-web/.env.production | 12 +++++++++++- main/manager-web/src/apis/httpRequest.js | 11 +++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/main/manager-web/.env.production b/main/manager-web/.env.production index 351d791a6e..168e984439 100644 --- a/main/manager-web/.env.production +++ b/main/manager-web/.env.production @@ -1,4 +1,14 @@ VUE_APP_API_BASE_URL=/xiaozhi VUE_APP_PUBLIC_PATH=/ # 是否开启CDN -VUE_APP_USE_CDN=false \ No newline at end of file +VUE_APP_USE_CDN=false +# 是否启用请求方法覆盖。默认关闭。 +# 某些服务器默认不支持 PUT、DELETE 方法,开启此配置后, +# 所有 PUT / DELETE 请求会被包装为 POST,并通过 X-HTTP-Method-Override 头传递原始方法。 +# 开启后,需在 nginx 的 location 区块中添加以下配置: +# set $method $request_method; +# if ($http_X_HTTP_Method_Override ~* 'PUT|DELETE') { +# set $method $http_X_HTTP_Method_Override; +# } +# proxy_method $method; +VUE_APP_HTTP_METHOD_OVERRIDE=false \ No newline at end of file diff --git a/main/manager-web/src/apis/httpRequest.js b/main/manager-web/src/apis/httpRequest.js index 245bf6cc7d..8615071789 100755 --- a/main/manager-web/src/apis/httpRequest.js +++ b/main/manager-web/src/apis/httpRequest.js @@ -30,10 +30,17 @@ function sendRequest() { if (isNotNull(store.getters.getToken)) { this._header.Authorization = 'Bearer ' + (JSON.parse(store.getters.getToken)).token } - + // 判断是否启用请求方法覆盖 + const shouldOverride = process.env.NODE_ENV === 'production' + && process.env.VUE_APP_HTTP_METHOD_OVERRIDE === 'true' + && ['PUT', 'DELETE'].includes(this._method) + const realMethod = shouldOverride ? 'POST' : this._method + if (shouldOverride) { + this._header['X-HTTP-Method-Override'] = this._method + } // 打印请求信息 fly.request(this._url, this._data, { - method: this._method, + method: realMethod, headers: this._header, responseType: this._responseType }).then((res) => {