From 4b0b07a8fbc5815ecf02d8885d378354961909e6 Mon Sep 17 00:00:00 2001 From: chouchoui Date: Sun, 28 Mar 2021 00:36:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0[BoxJs]:=20HTTP=20Backend?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=B8=8B=E4=BD=BF=E7=94=A8=E9=BB=98=E8=AE=A4?= =?UTF-8?q?API=E8=AF=B7=E6=B1=82=E8=B7=AF=E5=BE=84=EF=BC=88=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=BA=86HTTP=20Backend=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DPC=E8=BF=9C=E7=A8=8B=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=EF=BC=89=EF=BC=9B=E6=A0=BC=E5=BC=8F=E4=B8=8D=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E7=9A=84HTTP=20Backend=E4=B8=8D=E4=BC=9A=E7=94=9F=E6=95=88?= =?UTF-8?q?=EF=BC=88=E5=BD=93=E5=89=8D=E5=88=A4=E5=AE=9A=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E6=98=AFhttp:=E5=BC=80=E5=A4=B4=EF=BC=8C9999=E7=BB=93=E5=B0=BE?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index a125876ba..4a3bb6a82 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1847,6 +1847,12 @@

v{{ver.versio ) }, created() { + // 如果 url 参数中指定的 baseURL, 则后续的请求都请求到指定的域 + if (window.location.search) { + const [, baseURL] = /baseURL=(.*?)(&|$)/.exec(window.location.search) + axios.defaults.baseURL = baseURL || '' + this.ui.isCors = true + } // 根据路径跳转视图 const defview = '/' if (!this.isCors) { @@ -1860,21 +1866,11 @@

v{{ver.versio // 如果后端没有渲染数据, 则发出请求获取数据 if (this.boxServerData) { this.box = this.boxServerData + this.setHttpBackend() } else { axios.get('/query/boxdata').then((resp) => (this.box = resp.data)) + this.setHttpBackend() } - // 如果是Quantumult X环境并且配置了HTTP Backend,将axios请求指向到HTTP Backend - if (this.box.syscfgs.env === 'QuanX' && this.box.usercfgs.http_backend) { - axios.defaults.baseURL = this.box.usercfgs.http_backend - this.ui.isCors = true - } - // 如果 url 参数中指定的 baseURL, 则后续的请求都请求到指定的域 - if (window.location.search) { - const [, baseURL] = /baseURL=(.*?)(&|$)/.exec(window.location.search) - axios.defaults.baseURL = baseURL || '' - this.ui.isCors = true - } - // 获取全局备份 if (this.view === 'bak') { this.loadGlobalBak() @@ -2151,10 +2147,7 @@

v{{ver.versio Object.assign(this.box, resp.data) if (this.curapp.id === 'BoxSetting') { - if (this.box.syscfgs.env === 'QuanX') { - axios.defaults.baseURL = this.box.usercfgs.http_backend || '' - this.ui.isCors = true - } + this.setHttpBackend() } }) }, @@ -2395,6 +2388,24 @@

v{{ver.versio _v2 = v2.split('.'), _r = _v1[0] - _v2[0] return _r == 0 && v1 != v2 ? this.compareVersion(_v1.splice(1).join('.'), _v2.splice(1).join('.')) : _r + }, + // 设置HTTP Backend + setHttpBackend() { + // 目前HTTP Backend不能修改端口号 + var regex = /^http:\/\/(.*):9999$/ + if (this.box.syscfgs.env === 'QuanX') { + if (regex.test(window.location.origin)) { + axios.defaults.baseURL = '' + return + } + // 如果是Quantumult X环境并且配置了正确格式的HTTP Backend,将axios请求指向到HTTP Backend + if (this.box.usercfgs.http_backend && regex.test(this.box.usercfgs.http_backend)) { + axios.defaults.baseURL = this.box.usercfgs.http_backend + this.ui.isCors = true + } else { + axios.defaults.baseURL = '' + } + } } } }) From ced95c8a87c3c0fdfad105bfabf9e5da4853fffb Mon Sep 17 00:00:00 2001 From: chouchoui Date: Sun, 28 Mar 2021 00:48:00 +0800 Subject: [PATCH 2/3] fix promise --- box/chavy.boxjs.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 4a3bb6a82..6addb3e41 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1868,8 +1868,10 @@

v{{ver.versio this.box = this.boxServerData this.setHttpBackend() } else { - axios.get('/query/boxdata').then((resp) => (this.box = resp.data)) - this.setHttpBackend() + axios.get('/query/boxdata').then((resp) => { + this.box = resp.data + this.setHttpBackend() + }) } // 获取全局备份 if (this.view === 'bak') { From f7510e3144c7b9d80f7a7911587f13db817c26b4 Mon Sep 17 00:00:00 2001 From: Chavy Date: Sun, 28 Mar 2021 03:02:41 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0[BoxJs]:=20=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E7=89=88=E6=9C=AC=200.7.82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 12 ++++++++++++ box/release/box.release.tf.json | 12 ++++++++++++ chavy.box.js | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 45a397176..7aed06ef8 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.7.81' +$.version = '0.7.82' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 3e03ed983..cbe0a5563 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.7.82", + "tags": ["beta"], + "author": "@chouchoui", + "msg": "更新[BoxJs]: 格式不正确的HTTP Backend不会生效", + "notes": [ + { + "name": "优化", + "descs": ["格式不正确的HTTP Backend不会生效"] + } + ] + }, { "version": "0.7.81", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 06b57db31..84d4629f1 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.7.82", + "tags": ["beta"], + "author": "@chouchoui", + "msg": "更新[BoxJs]: 格式不正确的HTTP Backend不会生效", + "notes": [ + { + "name": "优化", + "descs": ["格式不正确的HTTP Backend不会生效"] + } + ] + }, { "version": "0.7.81", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 45a397176..7aed06ef8 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.7.81' +$.version = '0.7.82' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite