fix cors
This commit is contained in:
21
cors.go
21
cors.go
@@ -6,13 +6,26 @@ import (
|
|||||||
|
|
||||||
// Middleware function to handle CORS requests
|
// Middleware function to handle CORS requests
|
||||||
func handleCORS(c *gin.Context) {
|
func handleCORS(c *gin.Context) {
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, PATCH")
|
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Headers", "Origin, Authorization, Content-Type")
|
|
||||||
|
|
||||||
if c.Request.Method == "OPTIONS" {
|
if c.Request.Method == "OPTIONS" {
|
||||||
|
header := c.Writer.Header()
|
||||||
|
header.Set("Access-Control-Allow-Origin", "*")
|
||||||
|
header.Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, PATCH")
|
||||||
|
header.Set("Access-Control-Allow-Headers", "Origin, Authorization, Content-Type")
|
||||||
|
|
||||||
c.AbortWithStatus(200)
|
c.AbortWithStatus(200)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.Next()
|
||||||
|
|
||||||
|
header := c.Writer.Header()
|
||||||
|
|
||||||
|
header.Del("Access-Control-Allow-Origin")
|
||||||
|
header.Del("Access-Control-Allow-Methods")
|
||||||
|
header.Del("Access-Control-Allow-Headers")
|
||||||
|
|
||||||
|
header.Set("Access-Control-Allow-Origin", "*")
|
||||||
|
header.Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, PATCH")
|
||||||
|
header.Set("Access-Control-Allow-Headers", "Origin, Authorization, Content-Type")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user