Merge branch 'routing-capabilities' into route-loadbalancing

This commit is contained in:
Jonas Kaninda
2024-11-10 08:18:25 +01:00
4 changed files with 14 additions and 8 deletions

View File

@@ -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: "/",

View File

@@ -202,14 +202,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

View File

@@ -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 /

View File

@@ -15,6 +15,8 @@ import (
var Version string
const ConfigVersion = "1.0"
func VERSION(def string) string {
build := os.Getenv("VERSION")
if build == "" {