Skip to content

IgnoreBase parameter of the static middleware counter-intuitive #1933

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

Closed
wdscxsj opened this issue Jul 27, 2021 · 0 comments
Closed

IgnoreBase parameter of the static middleware counter-intuitive #1933

wdscxsj opened this issue Jul 27, 2021 · 0 comments

Comments

@wdscxsj
Copy link

wdscxsj commented Jul 27, 2021

I understand what IgnoreBase does but can't convince myself that it should be the preferred option (as suggested in #1701). Could we have some documentation to justify its proper use? Thanks!

Here is an example to show why I think NOT using it feels more natural.

package main

import (
	"net/http"

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

func main() {
	e := echo.New()
	g1 := e.Group("/a")
	g1.Use(middleware.StaticWithConfig(middleware.StaticConfig{
		Root:       "public",
		IgnoreBase: true,
	}))
	g2 := e.Group("/b")
	g2.Use(middleware.Static("public"))
	if err := e.Start("127.0.0.1:9000"); err != http.ErrServerClosed {
		e.Logger.Fatal(err)
	}
}

File system structure:

public/
    index.html  # says: public
    a/
        index.html  # says: outer a
        a/
            index.html  # says: inner a

Test:

$ curl http://localhost:9000/a/  # OK
public
$ curl http://localhost:9000/a/a  # really?
public
$ curl http://localhost:9000/a/a/a
outer a
$ curl http://localhost:9000/a/a/a/a  # so long?
inner a
$ curl http://localhost:9000/b/  # OK
public
$ curl http://localhost:9000/b/a  # OK
outer a
$ curl http://localhost:9000/b/a/a  # OK
inner a
@wdscxsj wdscxsj closed this as completed Aug 11, 2021
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

1 participant