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:
CityFun 2025-07-07 12:07:50 +08:00 committed by GitHub
parent 2bee68dd40
commit 54567db22f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 2 deletions

View file

@ -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),

View file

@ -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
}