From 1c15db2ca1db8189b9b5fb7df389af1ff2860be8 Mon Sep 17 00:00:00 2001 From: Anthony Accioly <1591739+aaccioly@users.noreply.github.com> Date: Thu, 31 Oct 2024 05:06:58 +0000 Subject: [PATCH] fix(blossom): CORS headers required by noStrudel --- blossom/server.go | 6 ++++++ blossom/utils.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/blossom/server.go b/blossom/server.go index 3b27962..653756f 100644 --- a/blossom/server.go +++ b/blossom/server.go @@ -33,6 +33,12 @@ func New(rl *khatru.Relay, serviceURL string) *BlossomServer { mux := http.NewServeMux() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.Method == "OPTIONS" { + setCors(w) + w.WriteHeader(http.StatusNoContent) + return + } + if r.URL.Path == "/upload" { if r.Method == "PUT" { setCors(w) diff --git a/blossom/utils.go b/blossom/utils.go index a9ec9cc..5af0d0d 100644 --- a/blossom/utils.go +++ b/blossom/utils.go @@ -7,8 +7,8 @@ import ( func setCors(w http.ResponseWriter) { w.Header().Set("Access-Control-Allow-Origin", "*") - w.Header().Set("Access-Control-Allow-Headers", "Authorization") - w.Header().Set("Access-Control-Allow-Methods", "GET PUT DELETE") + w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type") + w.Header().Set("Access-Control-Allow-Methods", "GET, PUT, DELETE, OPTIONS") } func blossomError(w http.ResponseWriter, msg string, code int) {