diff --git a/internal/config.go b/internal/config.go index 50b59c8..e02e780 100644 --- a/internal/config.go +++ b/internal/config.go @@ -118,7 +118,7 @@ func initConfig(configFile string) { configFile = GetConfigPaths() } conf := &GatewayConfig{ - Version: util.Version, + Version: util.ConfigVersion, GatewayConfig: Gateway{ WriteTimeout: 15, ReadTimeout: 15, @@ -165,7 +165,7 @@ func initConfig(configFile string) { }, { Name: "Hostname example", - Host: "http://example.localhost", + Hosts: []string{"example.com", "example.localhost"}, Path: "/", Destination: "https://example.com", Rewrite: "/", diff --git a/internal/route.go b/internal/route.go index ecfdfac..9de202b 100644 --- a/internal/route.go +++ b/internal/route.go @@ -197,14 +197,16 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router { router := r.PathPrefix(route.Path).Subrouter() // Apply route Cors router.Use(CORSHandler(route.Cors)) - if route.Host != "" { - router.Host(route.Host).PathPrefix("").Handler(proxyRoute.ProxyHandler()) + if len(route.Hosts) > 0 { + for _, host := range route.Hosts { + router.Host(host).PathPrefix("").Handler(proxyRoute.ProxyHandler()) + } } else { router.PathPrefix("").Handler(proxyRoute.ProxyHandler()) } } else { logger.Error("Error, path is empty in route %s", route.Name) - logger.Debug("Route path ignored: %s", route.Path) + logger.Error("Route path ignored: %s", route.Path) } } // Apply global Cors middlewares diff --git a/internal/types.go b/internal/types.go index 26963a5..c10ed3d 100644 --- a/internal/types.go +++ b/internal/types.go @@ -131,12 +131,14 @@ type MiddlewareName struct { // Route defines gateway route type Route struct { + // Path defines route path + Path string `yaml:"path"` // Name defines route name Name string `yaml:"name"` //Host Domain/host based request routing - Host string `yaml:"host"` - // Path defines route path - Path string `yaml:"path"` + //Host string `yaml:"host"` + //Hosts Domains/hosts based request routing + Hosts []string `yaml:"hosts"` // Rewrite rewrites route path to desired path // // E.g. /cart to / => It will rewrite /cart path to / diff --git a/util/constants.go b/util/constants.go index 5a15dff..6757d9b 100644 --- a/util/constants.go +++ b/util/constants.go @@ -15,6 +15,8 @@ import ( var Version string +const ConfigVersion = "1.0" + func VERSION(def string) string { build := os.Getenv("VERSION") if build == "" {