From ba4f7d7877dc7313213503b4d600a0860f83929b Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Thu, 29 Feb 2024 17:41:31 +0100 Subject: [PATCH] Fix fetching local http ressources on Chrome (#12546) --- server/http.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/http.go b/server/http.go index e043d2c20..adfdd7137 100644 --- a/server/http.go +++ b/server/http.go @@ -40,6 +40,15 @@ func NewHTTPd(addr string, hub *SocketHub) *HTTPd { return etag.Handler(h, false) }) + // allow requesting http assets from a non-private host. see https://developer.chrome.com/blog/cors-rfc1918-feedback?hl=de#step-2:-sending-preflight-requests-with-a-special-header + static.Use(func(next 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-Private-Network", "true") + next.ServeHTTP(w, r) + }) + }) + static.HandleFunc("/", indexHandler()) for _, dir := range []string{"assets", "meta"} { static.PathPrefix("/" + dir).Handler(http.FileServer(http.FS(assets.Web)))