diff --git a/src/servers/server.go b/src/servers/server.go index c01e00d5..94b7a306 100644 --- a/src/servers/server.go +++ b/src/servers/server.go @@ -52,7 +52,18 @@ func initMux(ctx context.Context) *mux.Router { apiRoute.HandleFunc("/file/{path:.*}", getFileInfo).Methods("GET") apiRoute.Handle("/metrics", promhttp.Handler()) - m.PathPrefix("/files/").Handler(http.StripPrefix("/files/", http.FileServer(http.Dir(instance.GetInstance(ctx).Config.OutPutPath)))) + m.PathPrefix("/files/").Handler( + CORSMiddleware( + http.StripPrefix( + "/files/", + http.FileServer( + http.Dir( + instance.GetInstance(ctx).Config.OutPutPath, + ), + ), + ), + ), + ) fs, err := webapp.FS() if err != nil { @@ -67,6 +78,15 @@ func initMux(ctx context.Context) *mux.Router { return m } +func CORSMiddleware(h 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-Methods", "POST, GET, OPTIONS, PUT, DELETE") + w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization") + h.ServeHTTP(w, r) + }) +} + func NewServer(ctx context.Context) *Server { inst := instance.GetInstance(ctx) config := inst.Config