added cors

This commit is contained in:
2023-01-29 22:33:48 +01:00
parent 6149845174
commit ee9867d80c

11
main.go
View File

@@ -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)