Skip to content

Commit a72b682

Browse files
committed
Fix port and route logic
1 parent 212fe63 commit a72b682

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

pkg/koyeb/services.go

+18-10
Original file line numberDiff line numberDiff line change
@@ -710,25 +710,33 @@ func (h *ServiceHandler) setDefaultPortsAndRoutes(definition *koyeb.DeploymentDe
710710
definition.SetPorts(h.getDeploymentPort(8000))
711711
definition.SetRoutes(h.getDeploymentRoute(8000))
712712

713-
// When one or more port are set but no route is set:
714-
// - if more than one port is set, we can't determine which one should be used to create the default route, so we return an error
715-
// - if exactly only one port is set, we create the default route with this port
713+
// When one or more ports are set but no route is explicitly configured:
714+
// - if only one HTTP port is defined, create the default route using that port
715+
// - if more than one HTTP port is set, we return an error as we can't determine routes configuration
716716
case len(currentPorts) > 0 && len(currentRoutes) == 0:
717-
if len(currentPorts) > 1 {
717+
httpPorts := []koyeb.DeploymentPort{}
718+
719+
for _, port := range currentPorts {
720+
if port.GetProtocol() == "http" {
721+
httpPorts = append(httpPorts, port)
722+
}
723+
}
724+
725+
if len(httpPorts) == 1 {
726+
definition.SetRoutes(h.getDeploymentRoute(httpPorts[0].GetPort()))
727+
}
728+
729+
if len(httpPorts) > 1 {
718730
return &errors.CLIError{
719731
What: "Error while configuring the service",
720-
Why: `your service has two or more ports set but no matching routes`,
732+
Why: `your service has two or more HTTP ports set but no matching routes`,
721733
Additional: []string{
722-
"For each port, you must specify a matching route with the --routes flag",
734+
"For each HTTP port, you must specify a matching route with the --routes flag",
723735
},
724736
Orig: nil,
725737
Solution: "Set the routes and try again",
726738
}
727739
}
728-
portNumber := currentPorts[0].GetPort()
729-
if currentPorts[0].GetProtocol() != "tcp" {
730-
definition.SetRoutes(h.getDeploymentRoute(portNumber))
731-
}
732740

733741
// If one or more routes are set but no port is set:
734742
// - if more than one route is set, we can't determine which one should be used to create the default port, so we return an error

0 commit comments

Comments
 (0)