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

It's not work when the server redirect 301. #56

Open
w4-hanggi opened this issue Jul 25, 2019 · 7 comments
Open

It's not work when the server redirect 301. #56

w4-hanggi opened this issue Jul 25, 2019 · 7 comments

Comments

@w4-hanggi
Copy link

It's ok when it return 200. but when the server return 301, cors not working.

@Louis-Amas
Copy link

this same problem using
In r.Group
Did you find a fix ?

@w4-hanggi
Copy link
Author

@Louis-Amas I almost forget this issue, I just changed my client request to sth like .../v1/foo/
Add '/' symbol at the end of the url to prevent redirection.

@JohnyTheLittle
Copy link

Id didnt work out. I did this according to your recommendation, but client side still throws CORS error.

@llxcyzgh
Copy link

It is not caused by gin-contrib/cors, it's caused by gin.
For "TrailingSlash" redirections, the process will get out before entering any middlewares.

@RiansyahTohamba
Copy link

RiansyahTohamba commented Sep 23, 2022

@Louis-Amas I almost forget this issue, I just changed my client request to sth like .../v1/foo/ Add '/' symbol at the end of the url to prevent redirection.

just in case you write '/' in the end of your url at golang server ( like /v1/foo/).

If you don't write it (like /v1/foo ), don't add '/' on your request url.

@BigBoulard
Copy link

BigBoulard commented Sep 19, 2023

You may want to check this answer gin-gonic/gin#1216 ...

   router := gin.New()

   friend := router.Group("/friend")
    {
      friend.GET("/", controller.GetFirends)
   }

Your router sets the handler to /friend/ path. You should use router.GET("", controller.GetFirends) if you want to use /friend :(without trailing slash).

@maczg
Copy link

maczg commented Sep 28, 2023

You may want to check this answer gin-gonic/gin#1216

I think the issue persist even setting specific route to .GET("", controller....) and calling /at the end of the path

My workaround: duplicate routes

   router := gin.New()

   friend := router.Group("/friend")
    {
      friend.GET("/", controller.GetFirends)
     friend.GET("", controller.GetFirends)
   }

So even if you call /friendor /friend/ no 301 redirect is returned

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

No branches or pull requests

7 participants