Fixed CORS
This commit is contained in:
parent
262293a2db
commit
4ee58e69ff
15
main.go
15
main.go
|
@ -207,6 +207,21 @@ func main() {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
router := gin.New()
|
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.Static("/static", "./static")
|
||||||
|
|
||||||
router.LoadHTMLGlob("templates/*.html")
|
router.LoadHTMLGlob("templates/*.html")
|
||||||
|
|
Reference in New Issue