chore: CORs option for yarn dev server (#7630)

* chore: Yarn dev servers require CORs headers for external proxies

Adds a flag to set CORs headers to `*` for yarn dev servers
This commit is contained in:
Steven Masley
2023-05-22 20:02:39 +02:00
committed by GitHub
parent 1f4f0efed6
commit 5d711fc95a
13 changed files with 80 additions and 18 deletions

View File

@ -6,7 +6,12 @@ import (
"strings"
)
func LatencyCheck(allowedOrigins ...*url.URL) http.HandlerFunc {
// LatencyCheck is an endpoint for the web ui to measure latency with.
// allowAll allows any Origin to get timing information. The allowAll should
// only be set in dev modes.
//
//nolint:revive
func LatencyCheck(allowAll bool, allowedOrigins ...*url.URL) http.HandlerFunc {
allowed := make([]string, 0, len(allowedOrigins))
for _, origin := range allowedOrigins {
// Allow the origin without a path
@ -14,6 +19,9 @@ func LatencyCheck(allowedOrigins ...*url.URL) http.HandlerFunc {
tmp.Path = ""
allowed = append(allowed, strings.TrimSuffix(origin.String(), "/"))
}
if allowAll {
allowed = append(allowed, "*")
}
origins := strings.Join(allowed, ",")
return func(rw http.ResponseWriter, r *http.Request) {
// Allowing timing information to be shared. This allows the browser