@@ -710,25 +710,33 @@ func (h *ServiceHandler) setDefaultPortsAndRoutes(definition *koyeb.DeploymentDe
710
710
definition .SetPorts (h .getDeploymentPort (8000 ))
711
711
definition .SetRoutes (h .getDeploymentRoute (8000 ))
712
712
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
716
716
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 {
718
730
return & errors.CLIError {
719
731
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` ,
721
733
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" ,
723
735
},
724
736
Orig : nil ,
725
737
Solution : "Set the routes and try again" ,
726
738
}
727
739
}
728
- portNumber := currentPorts [0 ].GetPort ()
729
- if currentPorts [0 ].GetProtocol () != "tcp" {
730
- definition .SetRoutes (h .getDeploymentRoute (portNumber ))
731
- }
732
740
733
741
// If one or more routes are set but no port is set:
734
742
// - 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