@@ -41,6 +41,7 @@ import (
41
41
oidc "github.com/coreos/go-oidc/v3/oidc"
42
42
"github.com/gobwas/glob"
43
43
"github.com/google/uuid"
44
+ "github.com/gorilla/handlers"
44
45
"github.com/gorilla/mux"
45
46
"github.com/kubernetes-sigs/headlamp/backend/pkg/auth"
46
47
"github.com/kubernetes-sigs/headlamp/backend/pkg/cache"
@@ -904,6 +905,40 @@ func processAndWriteProxyResponse(w http.ResponseWriter, resp *http.Response) er
904
905
return nil
905
906
}
906
907
908
+ func finalizeHandler (config * HeadlampConfig , router * mux.Router ) http.Handler {
909
+ if config .StaticDir != "" {
910
+ staticPath := config .StaticDir
911
+ if isWindows && strings .Contains (config .StaticDir , "/" ) {
912
+ staticPath = filepath .FromSlash (config .StaticDir )
913
+ }
914
+
915
+ spa := spaHandler {
916
+ staticPath : staticPath ,
917
+ indexPath : "index.html" ,
918
+ baseURL : config .BaseURL ,
919
+ }
920
+ router .PathPrefix ("/" ).Handler (spa )
921
+ }
922
+
923
+ if config .DevMode {
924
+ return setupCORS (router )
925
+ }
926
+
927
+ return router
928
+ }
929
+
930
+ func setupCORS (router * mux.Router ) http.Handler {
931
+ headers := handlers .AllowedHeaders ([]string {
932
+ "X-HEADLAMP_BACKEND-TOKEN" , "X-Requested-With" , "Content-Type" ,
933
+ "Authorization" , "Forward-To" ,
934
+ "KUBECONFIG" , "X-HEADLAMP-USER-ID" ,
935
+ })
936
+ methods := handlers .AllowedMethods ([]string {"GET" , "POST" , "PUT" , "HEAD" , "DELETE" , "PATCH" , "OPTIONS" })
937
+ origins := handlers .AllowedOrigins ([]string {"*" })
938
+
939
+ return handlers .CORS (headers , methods , origins )(router )
940
+ }
941
+
907
942
func getResponseReader (resp * http.Response ) (io.ReadCloser , error ) {
908
943
switch resp .Header .Get ("Content-Encoding" ) {
909
944
case "gzip" :
0 commit comments