feat: add cors middleware

This commit is contained in:
2025-12-24 16:33:13 -03:00
parent 56209011ec
commit 6f419ece3d
2 changed files with 23 additions and 3 deletions

View File

@@ -0,0 +1,19 @@
package middleware
import (
"net/http"
"os"
)
func CorsMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", os.Getenv("ALLOWED_ORIGIN"))
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
next.ServeHTTP(w, r)
})
}