mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-10 17:30:29 +08:00
自动纠正API节点相关地址填写的常见错误
This commit is contained in:
@@ -5,9 +5,12 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"net"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 添加地址
|
||||
// CreateAddrPopupAction 添加地址
|
||||
type CreateAddrPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
@@ -30,12 +33,31 @@ func (this *CreateAddrPopupAction) RunPost(params struct {
|
||||
Field("addr", params.Addr).
|
||||
Require("请输入访问地址")
|
||||
|
||||
// 兼容URL
|
||||
if regexp.MustCompile(`^(?i)(http|https)://`).MatchString(params.Addr) {
|
||||
u, err := url.Parse(params.Addr)
|
||||
if err != nil {
|
||||
this.FailField("addr", "错误的访问地址,不需要添加http://或https://")
|
||||
}
|
||||
params.Addr = u.Host
|
||||
}
|
||||
|
||||
// 自动添加端口
|
||||
if !strings.Contains(params.Addr, ":") {
|
||||
switch params.Protocol {
|
||||
case "http":
|
||||
params.Addr += ":80"
|
||||
case "https":
|
||||
params.Addr += ":443"
|
||||
}
|
||||
}
|
||||
|
||||
host, port, err := net.SplitHostPort(params.Addr)
|
||||
if err != nil {
|
||||
this.FailField("addr", "错误的访问地址")
|
||||
}
|
||||
|
||||
addrConfig := &serverconfigs.NetworkAddressConfig{
|
||||
var addrConfig = &serverconfigs.NetworkAddressConfig{
|
||||
Protocol: serverconfigs.Protocol(params.Protocol),
|
||||
Host: host,
|
||||
PortRange: port,
|
||||
|
||||
@@ -5,6 +5,9 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"net"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type UpdateAddrPopupAction struct {
|
||||
@@ -27,6 +30,26 @@ func (this *UpdateAddrPopupAction) RunPost(params struct {
|
||||
params.Must.
|
||||
Field("addr", params.Addr).
|
||||
Require("请输入访问地址")
|
||||
|
||||
// 兼容URL
|
||||
if regexp.MustCompile(`^(?i)(http|https)://`).MatchString(params.Addr) {
|
||||
u, err := url.Parse(params.Addr)
|
||||
if err != nil {
|
||||
this.FailField("addr", "错误的访问地址,不需要添加http://或https://")
|
||||
}
|
||||
params.Addr = u.Host
|
||||
}
|
||||
|
||||
// 自动添加端口
|
||||
if !strings.Contains(params.Addr, ":") {
|
||||
switch params.Protocol {
|
||||
case "http":
|
||||
params.Addr += ":80"
|
||||
case "https":
|
||||
params.Addr += ":443"
|
||||
}
|
||||
}
|
||||
|
||||
host, port, err := net.SplitHostPort(params.Addr)
|
||||
if err != nil {
|
||||
this.FailField("addr", "错误的访问地址")
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
|
||||
<h3>安装步骤</h3>
|
||||
<ol class="ui list">
|
||||
<li>按照下面的配置信息替换<code-label>configs/api.yaml</code-label>内容</li>
|
||||
<li>按照下面的配置信息替换<code-label>configs/db.yaml</code-label>内容</li>
|
||||
<li>按照下面的配置信息替换<code-label>configs/api.yaml</code-label>内容;如果文件不存在,请先创建</li>
|
||||
<li>按照下面的配置信息替换<code-label>configs/db.yaml</code-label>内容;如果文件不存在,请先创建</li>
|
||||
<li>使用<code-label>bin/edge-api start</code-label>启动节点</li>
|
||||
<li>可以在<code-label>logs/run.log</code-label>中查看启动是否有异常</li>
|
||||
<li>配置修改后,使用<code-label>bin/edge-api restart</code-label>重启节点</li>
|
||||
</ol>
|
||||
|
||||
<div class="ui divider"></div>
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
|
||||
<h3>安装步骤</h3>
|
||||
<ol class="ui list">
|
||||
<li>按照下面的配置信息替换<code-label>configs/api.yaml</code-label>内容</li>
|
||||
<li>按照下面的配置信息替换<code-label>configs/api.yaml</code-label>内容;如果文件不存在,请先创建</li>
|
||||
<li>使用<code-label>bin/edge-monitor start</code-label>启动节点</li>
|
||||
<li>可以在<code-label>logs/run.log</code-label>中查看启动是否有异常</li>
|
||||
<li>配置修改后,使用<code-label>bin/edge-monitor restart</code-label>重启节点</li>
|
||||
</ol>
|
||||
|
||||
<div class="ui divider"></div>
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
|
||||
<h3>安装步骤</h3>
|
||||
<ol class="ui list">
|
||||
<li>按照下面的配置信息替换<code-label>configs/api.yaml</code-label>内容</li>
|
||||
<li>按照下面的配置信息替换<code-label>configs/api.yaml</code-label>内容;如果文件不存在,请先创建</li>
|
||||
<li>使用<code-label>bin/edge-user start</code-label>启动节点</li>
|
||||
<li>可以在<code-label>logs/run.log</code-label>中查看启动是否有异常</li>
|
||||
<li>配置修改后,使用<code-label>bin/edge-user restart</code-label>重启节点</li>
|
||||
</ol>
|
||||
|
||||
<div class="ui divider"></div>
|
||||
|
||||
Reference in New Issue
Block a user