From ed59b558ea8ada029b50132d79fff79175189c15 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Sat, 18 Jul 2026 18:43:18 +0700 Subject: [PATCH] add cors --- cmd/evening_detective_server/main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/evening_detective_server/main.go b/cmd/evening_detective_server/main.go index 13ba376..597f83c 100644 --- a/cmd/evening_detective_server/main.go +++ b/cmd/evening_detective_server/main.go @@ -107,6 +107,7 @@ func main() { scenarioService, ), ) + // Serve gRPC server log.Println("Serving gRPC on 0.0.0.0:8080") go func() { @@ -142,10 +143,22 @@ func main() { gwServer := &http.Server{ Addr: ":8090", - Handler: mainMux, + Handler: cors(mainMux), } log.Println("Serving gRPC-Gateway on http://0.0.0.0:8090") log.Println("Serving docs on http://0.0.0.0:8090/docs") log.Fatalln(gwServer.ListenAndServe()) } + +func cors(h 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, PATCH, DELETE") + w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, Authorization, ResponseType, X-Id, X-Password") + if r.Method == "OPTIONS" { + return + } + h.ServeHTTP(w, r) + }) +}