Skip to content

Commit

Permalink
Fix fetching local http ressources on Chrome (#12546)
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis authored Feb 29, 2024
1 parent de60dab commit ba4f7d7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit ba4f7d7

Please sign in to comment.