Fix fetching local http ressources on Chrome (#12546)

This commit is contained in:
Michael Geers 2024-02-29 17:41:31 +01:00 • committed by GitHub
parent de60dab879
commit ba4f7d7877
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)))