Skip to content

IgnoreBase parameter of the static middleware counter-intuitive #1933

Closed
@wdscxsj

Description

@wdscxsj

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions