My API is served using the Echo framework. When I do a fetch
call from my React app, I get
Access to fetch at 'http://localhost:8080/myAPI' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
even though I'm setting up Echo like this:
srv := echo.New()
srv.HideBanner = true
srv.Use(middleware.Logger())
srv.Use(middleware.CORS())
I tried the following, but I get the same results:
var (
// DefaultCORSConfig is the default CORS middleware config.
DefaultCORSConfig = middleware.CORSConfig{
Skipper: middleware.DefaultSkipper,
AllowOrigins: []string{"*"},
AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete, http.MethodOptions},
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept, echo.HeaderAccessControlAllowOrigin, echo.HeaderAccessControlAllowMethods},
}
)
srv.Use(middleware.CORSWithConfig(DefaultCORSConfig))
In the response, I don't see the access-control-allow-origin
header. I get the same results even if I put localhost:3000
in AllowOrigins