TUN-7424: Add CORS headers to host_details responses

This commit is contained in:
Devin Carr
2023-05-16 22:18:57 -07:00
parent c43e07d6b7
commit cb97257815
8 changed files with 548 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import (
"time"
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
"github.com/google/uuid"
"github.com/rs/zerolog"
"nhooyr.io/websocket"
@@ -67,7 +68,17 @@ func New(managementHostname string,
r.Get("/ping", ping)
r.Head("/ping", ping)
r.Get("/logs", s.logs)
r.Get("/host_details", s.getHostDetails)
r.Route("/host_details", func(r chi.Router) {
// CORS middleware required to allow dash to access management.argotunnel.com requests
r.Use(cors.Handler(cors.Options{
// Allows for any subdomain of cloudflare.com
AllowedOrigins: []string{"https://*.cloudflare.com"},
// Required to present cookies or other authentication across origin boundries
AllowCredentials: true,
MaxAge: 300, // Maximum value not ignored by any of major browsers
}))
r.Get("/", s.getHostDetails)
})
s.router = r
return s
}