源站地址填写为HTTP时,自动检测HTTPS是否可用

This commit is contained in:
GoEdgeLab
2024-04-18 11:31:47 +08:00
parent 6be870d1d8
commit b2b6918329
9 changed files with 166 additions and 12 deletions

View File

@@ -18,10 +18,18 @@ Tea.context(function () {
this.changeProtocol = function () {
this.isOSS = this.protocol.startsWith("oss:")
if (this.protocol == "http") {
this.detectHTTPS()
} else {
this.adviceHTTPS = false
}
this.checkPort()
}
this.changeAddr = function () {
this.adviceHTTPS = false
if (this.serverType == "httpProxy") {
if (this.addr.startsWith("http://")) {
this.protocol = "http"
@@ -54,4 +62,42 @@ Tea.context(function () {
}
}
}
this.adviceHTTPS = false
var isDetectingHTTPS = false
this.detectHTTPS = function () {
if (isDetectingHTTPS) {
return
}
isDetectingHTTPS = true
this.adviceHTTPS = false
if (this.protocol == "http") {
this.$post("/servers/server/settings/origins/detectHTTPS")
.params({
addr: this.addr
})
.success(function (resp) {
this.adviceHTTPS = resp.data.isOk
if (resp.data.isOk) {
this.addr = resp.data.addr
}
})
.done(function () {
isDetectingHTTPS = false
})
} else {
isDetectingHTTPS = false
}
}
this.switchToHTTPS = function () {
this.adviceHTTPS = false
this.protocol = "https"
if (this.addr.endsWith(":80")) {
this.addr = this.addr.substring(0, this.addr.length - (":80").length)
}
}
})