Coder Social home page Coder Social logo

Comments (7)

w4-hanggi avatar w4-hanggi commented on June 1, 2024 2

@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.

from cors.

Louis-Amas avatar Louis-Amas commented on June 1, 2024

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

from cors.

JohnyTheLittle avatar JohnyTheLittle commented on June 1, 2024

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

from cors.

llxcyzgh avatar llxcyzgh commented on June 1, 2024

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.

from cors.

RiansyahTohamba avatar RiansyahTohamba commented on June 1, 2024

@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.

from cors.

BigBoulard avatar BigBoulard commented on June 1, 2024

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).

from cors.

maczg avatar maczg commented on June 1, 2024

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

from cors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.