diff --git a/README.md b/README.md index 8d76fe8..2d03ae2 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,8 @@ gateway: routes: # Example of a route | 1 - name: Store + # host Domain/host based request routing + host: localhost path: /store ## Rewrite a request path # e.g rewrite: /store to / diff --git a/goma.yml b/goma.yml index e37de40..5b846a8 100644 --- a/goma.yml +++ b/goma.yml @@ -34,6 +34,8 @@ gateway: routes: # Example of a route | 1 - name: Store + # host Domain/host based request routing + host: localhost path: /store ## Rewrite a request path # e.g rewrite: /store to / diff --git a/pkg/config.go b/pkg/config.go index 5fa7dba..c152f0c 100644 --- a/pkg/config.go +++ b/pkg/config.go @@ -105,6 +105,8 @@ type Route struct { Name string `yaml:"name"` // Path defines route path Path string `yaml:"path"` + //Host Domain/host based request routing + Host string `yaml:"host"` // Rewrite rewrites route path to desired path // // E.g. /cart to / => It will rewrite /cart path to / @@ -247,6 +249,7 @@ func initConfig(configFile string) { Routes: []Route{ { Name: "HealthCheck", + Host: "localhost", Path: "/public", Destination: "http://localhost:80", Rewrite: "/healthz", diff --git a/pkg/route.go b/pkg/route.go index c365f45..c57daaa 100644 --- a/pkg/route.go +++ b/pkg/route.go @@ -120,10 +120,14 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router { disableXForward: route.DisableHeaderXForward, cors: route.Cors, } - router := r.PathPrefix(route.Path).Subrouter() router.Use(CORSHandler(route.Cors)) - router.PathPrefix("").Handler(proxyRoute.ProxyHandler()) + //Domain/host based request routing + if route.Host != "" { + router.Host(route.Host).PathPrefix("").Handler(proxyRoute.ProxyHandler()) + } else { + router.PathPrefix("").Handler(proxyRoute.ProxyHandler()) + } } else { logger.Error("Error, path is empty in route %s", route.Name) logger.Info("Route path ignored: %s", route.Path)