use cors middleware

This commit is contained in:
2023-12-22 13:21:28 +08:00
parent b8ebbed5d6
commit 04a2e4c12d
3 changed files with 22 additions and 10 deletions

View File

@@ -85,12 +85,11 @@ func main() {
})
})
// CORS middleware
engine.Use(corsMiddleware())
// CORS handler
engine.OPTIONS("/v1/*any", func(ctx *gin.Context) {
header := ctx.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")
ctx.AbortWithStatus(200)
})