edit cors middleware
This commit is contained in:
parent
7a25952b1d
commit
41eae2ccc4
|
|
@ -18,8 +18,8 @@ type UsersController struct {
|
|||
|
||||
func (uc *UsersController) Route() {
|
||||
rg:= uc.rg.Group("/users")
|
||||
rg.Use(middleware.RateLoginMiddleware())
|
||||
rg.Use(middleware.CORSMiddleware())
|
||||
rg.Use(middleware.RateLoginMiddleware())
|
||||
rg.OPTIONS("/login", func(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -8,13 +8,12 @@ import (
|
|||
|
||||
func CORSMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*") // Change to specific domains if needed
|
||||
c.Writer.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE")
|
||||
c.Writer.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type, X-Requested-With")
|
||||
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
|
||||
c.Writer.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type")
|
||||
|
||||
// Handle OPTIONS method
|
||||
if c.Request.Method == "OPTIONS" {
|
||||
// Allow OPTIONS method to pass through
|
||||
if c.Request.Method == http.MethodOptions {
|
||||
c.AbortWithStatus(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue