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

CORS no longer works after upgrade to V4 #1874

Closed
ilovelili opened this issue May 13, 2021 · 2 comments
Closed

CORS no longer works after upgrade to V4 #1874

ilovelili opened this issue May 13, 2021 · 2 comments

Comments

@ilovelili
Copy link

Issue Description

We upgraded to echo V4 and found the 'Access-Control-Allow-Origin' response header no longer exists. The CORS example code however seems to be the same with V3. Is there any extra config needed in V4?

Checklist

  • [o] Dependencies installed
  • [o] No typos
  • [o] Searched existing issues and docs

Expected behaviour

'Access-Control-Allow-Origin' should show as response header

Actual behaviour

'Access-Control-Allow-Origin' not shown any more

Steps to reproduce

Working code to debug

package main

import (
	"net/http"
	"os"
	"strings"

	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
)

func main() {
	// Echo instance
	e := echo.New()

	e.HideBanner = true

	aos := []string{"*"}
	if os.Getenv("WS_ALLOW_ORIGINS") != "" {
		aos = strings.Split(os.Getenv("WS_ALLOW_ORIGINS"), ",")
	}

	cors := middleware.CORSWithConfig(middleware.CORSConfig{
		AllowOrigins: aos,
	})

	e.Use(cors)

	// Routes
	e.GET("/healthz", func(c echo.Context) error {
		return c.NoContent(http.StatusOK)
	})

	// Start server
	e.Logger.Fatal(e.Start(":1323"))
}

Version/commit

4.3.0

@aldas
Copy link
Contributor

aldas commented May 14, 2021

Seems to be releated to 871ed9c
See issue description for why it is so now #1668

When Origin header is empty all CORS logic in circumvented.

Some material related to CORS:

@ilovelili
Copy link
Author

I see. Thank you very much for your explanation @aldas !

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

2 participants