This commit is contained in:
jlau-ice 2025-09-09 19:07:55 +08:00 committed by GitHub
commit c90ce1295b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 3 deletions

View file

@ -1,4 +1,14 @@
VUE_APP_API_BASE_URL=/xiaozhi VUE_APP_API_BASE_URL=/xiaozhi
VUE_APP_PUBLIC_PATH=/ VUE_APP_PUBLIC_PATH=/
# 是否开启CDN # 是否开启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

View file

@ -30,10 +30,17 @@ function sendRequest() {
if (isNotNull(store.getters.getToken)) { if (isNotNull(store.getters.getToken)) {
this._header.Authorization = 'Bearer ' + (JSON.parse(store.getters.getToken)).token 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, { fly.request(this._url, this._data, {
method: this._method, method: realMethod,
headers: this._header, headers: this._header,
responseType: this._responseType responseType: this._responseType
}).then((res) => { }).then((res) => {