@@ -34,17 +34,16 @@ func CORSHandler(cors Cors) mux.MiddlewareFunc {
|
|||||||
w.Header().Set(k, v)
|
w.Header().Set(k, v)
|
||||||
}
|
}
|
||||||
//Update Origin Cors Headers
|
//Update Origin Cors Headers
|
||||||
for _, origin := range cors.Origins {
|
if allowedOrigin(cors.Origins, r.Header.Get("Origin")) {
|
||||||
if origin == r.Header.Get("Origin") {
|
// Handle preflight requests (OPTIONS)
|
||||||
w.Header().Set("Access-Control-Allow-Origin", origin)
|
if r.Method == "OPTIONS" {
|
||||||
|
w.Header().Set(accessControlAllowOrigin, r.Header.Get("Origin"))
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
w.Header().Set(accessControlAllowOrigin, r.Header.Get("Origin"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Handle preflight requests (OPTIONS)
|
|
||||||
if r.Method == "OPTIONS" {
|
|
||||||
w.WriteHeader(http.StatusNoContent)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Pass the request to the next handler
|
// Pass the request to the next handler
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
@@ -118,3 +117,13 @@ func (heathRoute HealthCheckRoute) HealthReadyHandler(w http.ResponseWriter, r *
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func allowedOrigin(origins []string, origin string) bool {
|
||||||
|
for _, o := range origins {
|
||||||
|
if o == origin {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
20
pkg/proxy.go
20
pkg/proxy.go
@@ -43,19 +43,17 @@ func (proxyRoute ProxyRoute) ProxyHandler() http.HandlerFunc {
|
|||||||
for k, v := range proxyRoute.cors.Headers {
|
for k, v := range proxyRoute.cors.Headers {
|
||||||
w.Header().Set(k, v)
|
w.Header().Set(k, v)
|
||||||
}
|
}
|
||||||
|
if allowedOrigin(proxyRoute.cors.Origins, r.Header.Get("Origin")) {
|
||||||
//Update Origin Cors Headers
|
// Handle preflight requests (OPTIONS)
|
||||||
for _, origin := range proxyRoute.cors.Origins {
|
if r.Method == "OPTIONS" {
|
||||||
if origin == r.Header.Get("Origin") {
|
w.Header().Set(accessControlAllowOrigin, r.Header.Get("Origin"))
|
||||||
w.Header().Set(accessControlAllowOrigin, origin)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
w.Header().Set(accessControlAllowOrigin, r.Header.Get("Origin"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Handle preflight requests (OPTIONS)
|
|
||||||
if r.Method == "OPTIONS" {
|
|
||||||
w.WriteHeader(http.StatusNoContent)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Parse the target backend URL
|
// Parse the target backend URL
|
||||||
targetURL, err := url.Parse(proxyRoute.destination)
|
targetURL, err := url.Parse(proxyRoute.destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router {
|
|||||||
// Add rate limit middleware to all routes, if defined
|
// Add rate limit middleware to all routes, if defined
|
||||||
r.Use(limiter.RateLimitMiddleware())
|
r.Use(limiter.RateLimitMiddleware())
|
||||||
}
|
}
|
||||||
// Add the errorInterceptor middleware
|
|
||||||
//r.Use(middleware.ErrorInterceptor)
|
|
||||||
for _, route := range gateway.Routes {
|
for _, route := range gateway.Routes {
|
||||||
if route.Path != "" {
|
if route.Path != "" {
|
||||||
blM := middleware.BlockListMiddleware{
|
blM := middleware.BlockListMiddleware{
|
||||||
|
|||||||
Reference in New Issue
Block a user