Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQ] [go-gin-server] Add featureCORS option to enable CORS middleware #11186

Open
kumo-rn5s opened this issue Dec 27, 2021 · 2 comments
Open

Comments

@kumo-rn5s
Copy link

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()
@wing328
Copy link
Member

wing328 commented Jan 4, 2022

@FirosStuart thanks for the suggestion. Can you please file a PR with the suggested enhancement?

@kumo-rn5s
Copy link
Author

Ok, I'll try that. I don't have experience contributing to this repository though, this might take some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants