From 4ee58e69ffddb6e802580f37162d4467bc9eea7a Mon Sep 17 00:00:00 2001 From: Arzumify Date: Sun, 28 Apr 2024 10:55:38 +0100 Subject: [PATCH] Fixed CORS --- main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.go b/main.go index 6ea9517..6e95144 100644 --- a/main.go +++ b/main.go @@ -207,6 +207,21 @@ func main() { gin.SetMode(gin.ReleaseMode) router := gin.New() + // Enable CORS + router.Use(func(c *gin.Context) { + c.Writer.Header().Set("Access-Control-Allow-Origin", "*") + c.Writer.Header().Set("Access-Control-Allow-Headers", "*") + c.Writer.Header().Set("Access-Control-Allow-Methods", "*") + + // Handle preflight requests + if c.Request.Method == "OPTIONS" { + c.AbortWithStatus(200) + return + } + + c.Next() + }) + router.Static("/static", "./static") router.LoadHTMLGlob("templates/*.html")