8000 Merge pull request #328 from chouchoui/master · webdev123456/scripts@88848f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 88848f2

Browse files
authored
Merge pull request #328 from chouchoui/master
更新[BoxJs]: HTTP Backend环境下使用默认API请求路径;格式不正确的HTTP Backend不会生效
2 parents 497dfd5 + f7510e3 commit 88848f2

File tree

5 files changed

+56
-19
lines changed

5 files changed

+56
-19
lines changed

box/chavy.boxjs.html

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,12 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
18471847
)
18481848
},
18491849
created() {
1850+
// 如果 url 参数中指定的 baseURL, 则后续的请求都请求到指定的域
1851+
if (window.location.search) {
1852+
const [, baseURL] = /baseURL=(.*?)(&|$)/.exec(window.location.search)
1853+
axios.defaults.baseURL = baseURL || ''
1854+
this.ui.isCors = true
1855+
}
18501856
// 根据路径跳转视图
18511857
const defview = '/'
18521858
if (!this.isCors) {
@@ -1860,21 +1866,13 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
18601866
// 如果后端没有渲染数据, 则发出请求获取数据
18611867
if (this.boxServerData) {
18621868
this.box = this.boxServerData
1869+
this.setHttpBackend()
18631870
} else {
1864-
axios.get('/query/boxdata').then((resp) => (this.box = resp.data))
1865-
}
1866-
// 如果是Quantumult X环境并且配置了HTTP Backend,将axios请求指向到HTTP Backend
1867-
if (this.box.syscfgs.env === 'QuanX' && this.box.usercfgs.http_backend) {
1868-
axios.defaults.baseURL = this.box.usercfgs.http_backend
1869-
this.ui.isCors = true
1870-
}
1871-
// 如果 url 参数中指定的 baseURL, 则后续的请求都请求到指定的域
1872-
if (window.location.search) {
1873-
const [, baseURL] = /baseURL=(.*?)(&|$)/.exec(window.location.search)
1874-
axios.defaults.baseURL = baseURL || ''
1875-
this.ui.isCors = true
1871+
axios.get('/query/boxdata').then((resp) => {
1872+
this.box = resp.data
1873+
this.setHttpBackend()
1874+
})
18761875
}
1877-
18781876
// 获取全局备份
18791877
if (this.view === 'bak') {
18801878
this.loadGlobalBak()
@@ -2151,10 +2149,7 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
21512149
Object.assign(this.box, resp.data)
21522150

21532151
if (this.curapp.id === 'BoxSetting') {
2154-
if (this.box.syscfgs.env === 'QuanX') {
2155-
axios.defaults.baseURL = this.box.usercfgs.http_backend || ''
2156-
this.ui.isCors = true
2157-
}
2152+
this.setHttpBackend()
21582153
}
21592154
})
21602155
},
@@ -2395,6 +2390,24 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
23952390
_v2 = v2.split('.'),
23962391
_r = _v1[0] - _v2[0]
23972392
return _r == 0 && v1 != v2 ? this.compareVersion(_v1.splice(1).join('.'), _v2.splice(1).join('.')) : _r
2393+
},
2394+
// 设置HTTP Backend
2395+
setHttpBackend() {
2396+
// 目前HTTP Backend不能修改端口号
2397+
var regex = /^http:\/\/(.*):9999$/
2398+
if (this.box.syscfgs.env === 'QuanX') {
2399+
if (regex.test(window.location.origin)) {
2400+
axios.defaults.baseURL = ''
2401+
return
2402+
}
2403+
// 如果是Quantumult X环境并且配置了正确格式的HTTP Backend,将axios请求指向到HTTP Backend
2404+
if (this.box.usercfgs.http_backend && regex.test(this.box.usercfgs.http_backend)) {
2405+
axios.defaults.baseURL = this.box.usercfgs.http_backend
2406+
this.ui.isCors = true
2407+
} else {
2408+
axios.defaults.baseURL = ''
2409+
}
2410+
}
23982411
}
23992412
}
24002413
})

box/chavy.boxjs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const $ = new Env('BoxJs')
33
// 为 eval 准备的上下文环境
44
const $eval_env = {}
55

6-
$.version = '0.7.81'
6+
$.version = '0.7.82'
77
$.versionType = 'beta'
88

99
// 发出的请求需要需要 Surge、QuanX 的 rewrite

box/release/box.release.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
{
22
"releases": [
3+
{
4+
"version": "0.7.82",
5+
"tags": ["beta"],
6+
"author": "@chouchoui",
7+
"msg": "更新[BoxJs]: 格式不正确的HTTP Backend不会生效",
8+
"notes": [
9+
{
10+
"name": "优化",
11+
"descs": ["格式不正确的HTTP Backend不会生效"]
12+
}
13+
]
14+
},
315
{
416
"version": "0.7.81",
517
"tags": ["beta"],

box/release/box.release.tf.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
{
22
"releases": [
3+
{
4+
"version": "0.7.82",
5+
"tags": ["beta"],
6+
"author": "@chouchoui",
7+
"msg": "更新[BoxJs]: 格式不正确的HTTP Backend不会生效",
8+
"notes": [
9+
{
10+
"name": "优化",
11+
"descs": ["格式不正确的HTTP Backend不会生效"]
12+
}
13+
]
14+
},
315
{
416
"version": "0.7.81",
517
"tags": ["beta"],

chavy.box.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const $ = new Env('BoxJs')
33
// 为 eval 准备的上下文环境
44
const $eval_env = {}
55

6-
$.version = '0.7.81'
6+
$.version = '0.7.82'
77
$.versionType = 'beta'
88

99
// 发出的请求需要需要 Surge、QuanX 的 rewrite

0 commit comments

Comments
 (0)
0