fix: fix route path that not ends with /

This commit is contained in:
Jonas Kaninda
2024-10-28 03:26:32 +01:00
parent d9cc629a4c
commit 5e4f5f4054
3 changed files with 15 additions and 18 deletions

View File

@@ -247,30 +247,23 @@ func initConfig(configFile string) {
Routes: []Route{ Routes: []Route{
{ {
Name: "HealthCheck", Name: "HealthCheck",
Path: "/healthy", Path: "/public",
Destination: "http://localhost:8080", Destination: "http://localhost:80",
Rewrite: "/health", Rewrite: "/healthz",
HealthCheck: "", HealthCheck: "",
Cors: Cors{
Headers: map[string]string{
"Access-Control-Allow-Headers": "Origin, Authorization, Accept, Content-Type, Access-Control-Allow-Headers, X-Client-Id, X-Session-Id",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Max-Age": "1728000",
},
},
}, },
{ {
Name: "Basic auth", Name: "Basic auth",
Path: "/basic", Path: "/protected",
Destination: "http://localhost:8080", Destination: "https://example.com",
Rewrite: "/health", Rewrite: "/",
HealthCheck: "", HealthCheck: "",
Blocklist: []string{}, Blocklist: []string{},
Cors: Cors{}, Cors: Cors{},
Middlewares: []RouteMiddleware{ Middlewares: []RouteMiddleware{
{ {
Path: "/basic/auth", Path: "/user",
Rules: []string{"basic-auth", "google-jwt"}, Rules: []string{"basic-auth"},
}, },
}, },
}, },
@@ -285,10 +278,13 @@ func initConfig(configFile string) {
Password: "goma", Password: "goma",
}, },
}, { }, {
Name: "google-jwt", Name: "jwt",
Type: "jwt", Type: "jwt",
Rule: JWTRuler{ Rule: JWTRuler{
URL: "https://www.googleapis.com/auth/userinfo.email", URL: "https://www.googleapis.com/auth/userinfo.email",
RequiredHeaders: []string{
"Authorization",
},
Headers: map[string]string{}, Headers: map[string]string{},
Params: map[string]string{}, Params: map[string]string{},
}, },

View File

@@ -107,6 +107,7 @@ func (heathRoute HealthCheckRoute) HealthCheckHandler(w http.ResponseWriter, r *
} }
func (heathRoute HealthCheckRoute) HealthReadyHandler(w http.ResponseWriter, r *http.Request) { func (heathRoute HealthCheckRoute) HealthReadyHandler(w http.ResponseWriter, r *http.Request) {
response := HealthCheckRouteResponse{ response := HealthCheckRouteResponse{
Name: "Goma Gateway",
Status: "healthy", Status: "healthy",
Error: "", Error: "",
} }

View File

@@ -123,7 +123,7 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router {
router := r.PathPrefix(route.Path).Subrouter() router := r.PathPrefix(route.Path).Subrouter()
router.Use(CORSHandler(route.Cors)) router.Use(CORSHandler(route.Cors))
router.PathPrefix("/").Handler(proxyRoute.ProxyHandler()) router.PathPrefix("").Handler(proxyRoute.ProxyHandler())
} else { } else {
logger.Error("Error, path is empty in route %s", route.Name) logger.Error("Error, path is empty in route %s", route.Name)
logger.Info("Route path ignored: %s", route.Path) logger.Info("Route path ignored: %s", route.Path)