Set Access-Control-Allow-Origin for HTTP error responses as well.

This commit is contained in:
Catherine
2025-09-16 17:12:45 +00:00
parent b7e16b5e5f
commit e0f6dabd9f

View File

@@ -76,6 +76,10 @@ func getPage(w http.ResponseWriter, r *http.Request) error {
}
}
// allow JavaScript code to access responses (including errors) even across origins
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Max-Age", "86400")
// decide on the HTTP status
if err != nil {
if errors.Is(err, os.ErrNotExist) {
@@ -90,10 +94,6 @@ func getPage(w http.ResponseWriter, r *http.Request) error {
// serve custom 404 page (if any)
io.Copy(w, reader)
} else {
// allow JavaScript code to download files even across origins
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Max-Age", "86400")
// allow the use of multi-threading in WebAssembly
w.Header().Set("Cross-Origin-Embedder-Policy", "credentialless")
w.Header().Set("Cross-Origin-Opener-Policy", "same-origin")