From 6516b457cbabde2cd8bef6116501bde4db588305 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 30 Dec 2024 12:02:16 +0530 Subject: [PATCH] [server] Add workaround for intermittent Safari CORS errors At times, Safari will fail our API responses because its CORS preflight fails. The errors are reproducible, but intermittently, and not on localhost. We seem not to be the first ones to hit [this](https://github.com/processing/p5.js-web-editor/issues/3156). Based on a hint from: https://github.com/supabase/supabase/issues/20982#issuecomment-2548329565 Modify our CORS responses to use 200 instead of 204 to try and fix Safari. --- server/cmd/museum/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.go index 22199d18e1..a4622e1b70 100644 --- a/server/cmd/museum/main.go +++ b/server/cmd/museum/main.go @@ -1007,7 +1007,9 @@ func cors() gin.HandlerFunc { c.Writer.Header().Set("Access-Control-Max-Age", "1728000") if c.Request.Method == http.MethodOptions { - c.AbortWithStatus(http.StatusNoContent) + // While 204 No Content is more appropriate, Safari intermittently + // (intermittently!) fails CORS if we return 204 instead of 200 OK. + c.Status(http.StatusOK) return } c.Next()