fix(middleware): define middleware in a more streamlined way
All checks were successful
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 2m26s
All checks were successful
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 2m26s
This commit was merged in pull request #270.
This commit is contained in:
@@ -6,17 +6,18 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func EnableCors(serverSettings *types.ServerSettings, next http.Handler) http.Handler {
|
||||
func Cors(serverSettings *types.ServerSettings) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", serverSettings.BaseUrl)
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, DELETE")
|
||||
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", serverSettings.BaseUrl)
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, DELETE")
|
||||
if r.Method == "OPTIONS" {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
|
||||
if r.Method == "OPTIONS" {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user