fix cors
This commit is contained in:
5
cors.go
5
cors.go
@@ -5,8 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Middleware function to handle CORS requests
|
// Middleware function to handle CORS requests
|
||||||
func corsMiddleware() gin.HandlerFunc {
|
func handleCORS(c *gin.Context) {
|
||||||
return func(c *gin.Context) {
|
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
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-Methods", "POST, GET, OPTIONS, PUT, DELETE, PATCH")
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Headers", "Origin, Authorization, Content-Type")
|
c.Writer.Header().Set("Access-Control-Allow-Headers", "Origin, Authorization, Content-Type")
|
||||||
@@ -16,6 +15,4 @@ func corsMiddleware() gin.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Next()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -91,7 +91,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// CORS handler
|
// CORS handler
|
||||||
engine.Use(corsMiddleware())
|
engine.OPTIONS("/v1/*any", handleCORS)
|
||||||
|
|
||||||
// get authorization config from db
|
// get authorization config from db
|
||||||
db.Take(&authConfig, "key = ?", "authorization")
|
db.Take(&authConfig, "key = ?", "authorization")
|
||||||
|
|||||||
Reference in New Issue
Block a user