Disable CORS

Signed-off-by: Arzumify <jliwin98@danwin1210.de>
This commit is contained in:
Tracker-Friendly 2024-10-15 19:39:16 +01:00
parent 5492212611
commit b1e06cf673
1 changed files with 12 additions and 0 deletions

View File

@ -344,6 +344,18 @@ func Main(information library.ServiceInitializationInformation) *chi.Mux {
// Set up the router // Set up the router
router := chi.NewRouter() router := chi.NewRouter()
// Add the CORS middleware
disableCors := func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
next.ServeHTTP(w, r)
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "*")
w.Header().Set("Access-Control-Allow-Methods", "*")
})
}
router.Use(disableCors)
// Set up the static routes // Set up the static routes
staticDir, err := fs.Sub(information.ResourceDir, "static") staticDir, err := fs.Sub(information.ResourceDir, "static")
if err != nil { if err != nil {