Skip to content

Commit

Permalink
Merge pull request #328 from chouchoui/master
Browse files Browse the repository at this point in the history
更新[BoxJs]: HTTP Backend环境下使用默认API请求路径;格式不正确的HTTP Backend不会生效
  • Loading branch information
chavyleung authored Mar 27, 2021
2 parents 497dfd5 + f7510e3 commit 88848f2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 19 deletions.
47 changes: 30 additions & 17 deletions box/chavy.boxjs.html
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,12 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">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) {
Expand All @@ -1860,21 +1866,13 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
// 如果后端没有渲染数据, 则发出请求获取数据
if (this.boxServerData) {
this.box = this.boxServerData
this.setHttpBackend()
} else {
axios.get('/query/boxdata').then((resp) => (this.box = resp.data))
}
// 如果是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
axios.get('/query/boxdata').then((resp) => {
this.box = resp.data
this.setHttpBackend()
})
}

// 获取全局备份
if (this.view === 'bak') {
this.loadGlobalBak()
Expand Down Expand Up @@ -2151,10 +2149,7 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">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()
}
})
},
Expand Down Expand Up @@ -2395,6 +2390,24 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">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 = ''
}
}
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion box/chavy.boxjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions box/release/box.release.json
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
12 changes: 12 additions & 0 deletions box/release/box.release.tf.json
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion chavy.box.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 88848f2

Please sign in to comment.