diff --git a/hub/route/server.go b/hub/route/server.go index a3a387c91..8e7f225f4 100644 --- a/hub/route/server.go +++ b/hub/route/server.go @@ -63,6 +63,7 @@ func Start(addr string, tlsAddr string, secret string, AllowedHeaders: []string{"Content-Type", "Authorization"}, MaxAge: 300, }) + r.Use(setPrivateNetworkAccess) r.Use(corsM.Handler) if isDebug { r.Mount("/debug", func() http.Handler { @@ -149,6 +150,15 @@ func Start(addr string, tlsAddr string, secret string, } +func setPrivateNetworkAccess(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodOptions && r.Header.Get("Access-Control-Request-Method") != "" { + w.Header().Add("Access-Control-Allow-Private-Network", "true") + } + next.ServeHTTP(w, r) + }) +} + func safeEuqal(a, b string) bool { aBuf := utils.ImmutableBytesFromString(a) bBuf := utils.ImmutableBytesFromString(b)