-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Open
Labels
Description
Is your feature request related to a problem? Please describe.
Go-Gin-Server supporting file routers.go start a router without any cors configurations.
router := gin.Default()
for _, route := range routes {
switch route.Method {
case http.MethodGet:
router.GET(route.Pattern, route.HandlerFunc)
case http.MethodPost:
router.POST(route.Pattern, route.HandlerFunc)
case http.MethodPut:
router.PUT(route.Pattern, route.HandlerFunc)
case http.MethodPatch:
router.PATCH(route.Pattern, route.HandlerFunc)
case http.MethodDelete:
router.DELETE(route.Pattern, route.HandlerFunc)
}
}Describe the solution you'd like
Like Go-Server featureCORS option, cors configurations are added to router before route paths are holding, similar processing is required by Go-Gin-Server.
https://github.com/gin-contrib/cors
router := gin.Default()
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"https://foo.com"},
AllowMethods: []string{"PUT", "PATCH"},
AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return origin == "https://github.com"
},
MaxAge: 12 * time.Hour,
}))
router.Run()Reactions are currently unavailable