Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion main/manager-web/.env.production
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
VUE_APP_API_BASE_URL=/xiaozhi
VUE_APP_PUBLIC_PATH=/
# 是否开启CDN
VUE_APP_USE_CDN=false
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
11 changes: 9 additions & 2 deletions main/manager-web/src/apis/httpRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down