Skip to content

Echo.get("*") is responding to every route even when others are defined #2493

Closed Answered by aldas
GrimBit1 asked this question in Q&A
Discussion options

You must be logged in to vote

Your problem is that

e.Static("/", "build")

and

	e.Get("*",func(c echo.Context) error {
		return c.File("index.html")
	})

are actually same route path and when exactly same path is added by e.Get it overrides path registered with e.Static

Do I understand correctly that you want to build SPA? where static assets are served from path that are not handler.Apihandler paths? If so I suggest using middleware.StaticWithConfig for that usecase.

Try this example:

func main() {
	e := echo.New()

	e.Use(middleware.Logger())
	e.Use(middleware.AddTrailingSlash())

	e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
		Skipper: nil,
		// Root directory from where the static content is served.
		R…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@aldas
Comment options

Answer selected by aldas
@GrimBit1
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants