fix(cors): add CORS middleware
build / Go-Build (push) Successful in 1m28s

This commit is contained in:
2026-05-26 00:48:00 +02:00
parent 54a16fab4a
commit d891321780
2 changed files with 22 additions and 2 deletions
+16
View File
@@ -0,0 +1,16 @@
package server
import "net/http"
func corsMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-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)
})
}