Skip to content

Commit

Permalink
[server] Add workaround for intermittent Safari CORS errors
Browse files Browse the repository at this point in the history
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](processing/p5.js-web-editor#3156).

Based on a hint from:

supabase/supabase#20982 (comment)

Modify our CORS responses to use 200 instead of 204 to try and fix Safari.
  • Loading branch information
mnvr committed Dec 30, 2024
1 parent bf78b2e commit 6516b45
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server/cmd/museum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6516b45

Please sign in to comment.