feat: add multiple hosts rounting capabilities
This commit is contained in:
@@ -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: "/",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 /
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
|
||||
var Version string
|
||||
|
||||
const ConfigVersion = "1.0"
|
||||
|
||||
func VERSION(def string) string {
|
||||
build := os.Getenv("VERSION")
|
||||
if build == "" {
|
||||
|
||||
Reference in New Issue
Block a user