From ee9867d80ced70b58c126297c942e191356a9776 Mon Sep 17 00:00:00 2001 From: Tilo Klarenbeek Date: Sun, 29 Jan 2023 22:33:48 +0100 Subject: [PATCH] added cors --- main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 43246ee..57b7413 100644 --- a/main.go +++ b/main.go @@ -125,6 +125,15 @@ func loadCurrent() { } } +func cors(fs http.Handler) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // do your cors stuff + // return if you do not want the FileServer handle a specific request + + fs.ServeHTTP(w, r) + } +} + func main() { loadCurrent() @@ -139,7 +148,7 @@ func main() { }() fs := http.FileServer(http.Dir("./data")) - http.Handle("/", fs) + http.Handle("/", cors(fs)) log.Print("Listening on :60002...") err := http.ListenAndServe(":60002", nil)