mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-09-11 09:05:51 +08:00
Fix: Resolved issue where domain binding failed in MCP due to OpenResty not using 80 port (#9435)
Refs https://github.com/1Panel-dev/1Panel/issues/9431
This commit is contained in:
parent
2bee68dd40
commit
54567db22f
2 changed files with 30 additions and 2 deletions
|
@ -283,11 +283,19 @@ func (m McpServerService) BindDomain(req request.McpBindDomain) error {
|
|||
}
|
||||
}
|
||||
group, _ := groupRepo.Get(groupRepo.WithByWebsiteDefault())
|
||||
|
||||
domain, err := ParseDomain(req.Domain)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if domain.Port == 0 {
|
||||
domain.Port = nginxInstall.HttpPort
|
||||
}
|
||||
createWebsiteReq := request.WebsiteCreate{
|
||||
Domains: []request.WebsiteDomain{
|
||||
{
|
||||
Domain: req.Domain,
|
||||
Port: 80,
|
||||
Domain: domain.Domain,
|
||||
Port: domain.Port,
|
||||
},
|
||||
},
|
||||
Alias: strings.ToLower(req.Domain),
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -1443,3 +1444,22 @@ func hasDefaultServer(params []string) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ParseDomain(domain string) (*model.WebsiteDomain, error) {
|
||||
host, portStr, err := net.SplitHostPort(domain)
|
||||
if err != nil {
|
||||
return &model.WebsiteDomain{
|
||||
Domain: domain,
|
||||
Port: 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
port, err := strconv.Atoi(portStr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid port in domain %s: %v", domain, err)
|
||||
}
|
||||
return &model.WebsiteDomain{
|
||||
Domain: host,
|
||||
Port: port,
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue