Fixed CORS

This commit is contained in:
Tracker-Friendly 2024-04-28 10:55:38 +01:00
parent 262293a2db
commit 4ee58e69ff
1 changed files with 15 additions and 0 deletions

15
main.go
View File

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