Coder Social home page Coder Social logo

Comments (3)

jub0bs avatar jub0bs commented on May 20, 2024

@rpstw Note that curl -vL -X OPTIONS '10.20.0.23:3323/some-path?' -H Origin:https://some-origin.com does not correspond to a CORS-preflight request: it's missing an Access-Control-Request-Method header. Therefore, I wouldn't expect a properly implemented CORS middleware to include CORS headers in a response to such a request.

As for applying different CORS middleware on different routes, I believe that Echo allows you to do that. This example uses a different CORS library, but you should be able to adapt it to your needs.

from echo.

aldas avatar aldas commented on May 20, 2024

When you add GET route with CORS middleware with

e.Add(
	http.MethodGet,
	"/some/path",
	SomeHandlerFunc,
	middleware.CORSWithConfig(middleware.CORSConfig{
		AllowCredentials: true,
	}),
)

Echo router registers only node matching GET method in its internal routing tree. So when you issue OPTION method call to same path the CORS middleware do not get executed as it is tied (wrapping it) to GET handler. So CORS middleware is best to be used with e.Use() by it to all routes or registering .OPTIONS("path"... to be able to match only some of the requests

p.s. if choose to register own OPTIONS routes you can use echo.MethodNotAllowedHandler handler function

echo/echo.go

Line 356 in 88c379f

var MethodNotAllowedHandler = func(c Context) error {

from echo.

rpstw avatar rpstw commented on May 20, 2024

Thanks for the explanation.

from echo.

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.