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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Static path with trailing slashes doesn't work! #1490

Closed
imraan-go opened this issue Aug 15, 2021 · 9 comments 路 Fixed by #1556
Closed

馃悰 Static path with trailing slashes doesn't work! #1490

imraan-go opened this issue Aug 15, 2021 · 9 comments 路 Fixed by #1556

Comments

@imraan-go
Copy link

Fiber version
v2.17.0
Issue description
Static path with trailing slashes does not work! When path ends with slash like /docs/ or docs/ , the path is not found!
Code snippet

package main

import "github.com/gofiber/fiber/v2"

func main() {
  app := fiber.New()
app.Static("/docs", "./docs/slate/build/") // -> http://localhost:3000/docs  Works.
app.Static("/docs/", "./docs/slate/build/") // -> http://localhost:3000/docs/ Doesn't work! 404 Not found



  // Steps to reproduce

  log.Fatal(app.Listen(":3000"))
}
@welcome
Copy link

welcome bot commented Aug 15, 2021

Thanks for opening your first issue here! 馃帀 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@IGLOU-EU
Copy link

Even if you try to force StrictRouting to false in Config struct ?
https://pkg.go.dev/github.com/gofiber/fiber/v2#Config

@imraan-go
Copy link
Author

Even if you try to force StrictRouting to false in Config struct ?
https://pkg.go.dev/github.com/gofiber/fiber/v2#Config

StrictRouting is false by default! This has nothing to do with strict routing. The problem is with Static method. app.Get("/products/", SearchProducts) This works perfectly fine with default settings.I can browse http://localhost/products/ But app.Static("/docs/", "./docs/slate/build/") shows 404 Not found.

@ReneWerner87
Copy link
Member

could be that the error lies there

https://github.com/valyala/fasthttp/blob/master/fs.go#L978

@imraan-go
Copy link
Author

imraan-go commented Aug 18, 2021

This is not related to fasthttp. I just tried debugging it, looks like the handler does not get called at all in handler variable in registerStatic method. So seems like fiber is unable to set the router properly when static path ends with slashes.

@fufuok
Copy link
Contributor

fufuok commented Oct 1, 2021

May be fixed by #1538

@fufuok
Copy link
Contributor

fufuok commented Oct 1, 2021

image

image

image

package main

import (
	"github.com/gofiber/fiber/v2"
)

func main() {
	app := fiber.New()
	app.Static("/web", "./web")
	app.Listen(":3000")
}

go.mod

module tmp_static_web

go 1.15

require github.com/gofiber/fiber/v2 v2.19.1-0.20211001105148-b94870d8865b

tmp_static_web.211001.zip

@fufuok
Copy link
Contributor

fufuok commented Oct 1, 2021

If you want to use trailing slash to register static file routing, then you may need such modification.

@ReneWerner87 if necessary, I can PR.

image

demo

package main

import (
	"github.com/gofiber/fiber/v2"
)

func main() {
	app := fiber.New()
	app.Static("/static", "./public", fiber.Static{
		Browse: true,
	})
	app.Static("/test_static/", "./public", fiber.Static{
		Browse: true,
	})
	app.Static("/web", "./public/web")
	app.Static("/test_web/", "./public/web")
	app.Listen(":3000")
}

go.mod

module tmp_static_trailing_slash

go 1.15

require github.com/gofiber/fiber/v2 v2.19.0

replace github.com/gofiber/fiber/v2 v2.19.0 => github.com/fufuok/fiber/v2 v2.19.1-0.20211001150354-c126d46683c1

You can visit the following URL:

demo code

tmp_static_trailing_slash_fixed.211001.zip

@suntong
Copy link

suntong commented Oct 11, 2021

Haha, reported that before in #705, which had been closed without giving any reason.
Thanks @fufuok for finally make it works. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants