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
馃悰 Can't find index.html with PathPrefix? #1439
Comments
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 |
The pathPrefix is used in front of the index path. Please test it with "index.html" |
@ReneWerner87 sorry mate - i played around a ton with this and tried that just to see if it worked. Updated my config above to be the actual one I have (my fault), and it's the same behavior. |
I'm having a similar problem, what's weird is:
Works just fine treating index.html as the index. But I can't access If I set PathPrefix to "static" or "static/" then it stops working, but I can access |
Ah, I think I figured it out, it's due to how the paths are being prefixed with You can easily reproduce this with:
Here's the offending code filesystem.go#L91:
|
yes, i also found the errors, the filesytem middleware is not yet fully ready for embedded filesystems these filesystems behave a little bit different, so the index file can not be found, if i have time today, i will try to provide a fix |
Thanks both of y'all. I'm coming over to Golang from NodeJS and Express and I have to say Fiber has been a real treat to work with. 鉂わ笍 |
didn't make it today unfortunately, try to provide a fix on the weekend, if you have time before and find a solution, then feel free to create a pull request |
I took a crack at fixing this, but we are unfortunately out of luck testing the I tried with:
But i'm worried that all the other filesystems would fail with this. One option is to have a cfg option of ShouldStripPrefix set to false, but can be enabled for different file system types (but that's super ugly too). Not sure the best way to fix this without requiring additional information from the caller. |
Super janky, but it's a work around:
|
This seems possibly related to #1490. The workaround above wouldn't work for a situation where there's a directory without an index file but that does have an html file with the same name as the directory (this is how NextJs exports project structures by the way):
Fiber looks for \orgs\index.html, but if it's not there, does not find orgs.html, and instead says reading the directory '\orgs' is Forbidden. |
If that's the case, you can overwrite index file with |
I ran into this issue today, what I saw is the same behavior @wirepair described, the file, err = cfg.Root.Open("/testdata/") We could add an extra check after we add the prefix: if path != "/" && strings.HasSuffix(path, "/") {
path = strings.TrimSuffix(path, "/")
} |
this is doing it for me, while I wait for a proper fix.
|
go.mod module tmp_fiber_1439
go 1.17
require github.com/gofiber/fiber/v2 v2.19.1-0.20211005120320-587f3ae9df4b
require (
github.com/andybalholm/brotli v1.0.2 // indirect
github.com/klauspost/compress v1.13.4 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.29.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 // indirect
) test testCode |
fixed with #1547 release https://github.com/gofiber/fiber/releases/tag/v2.20.0 |
Fiber version
v2.14.0
Issue description
Getting a 404 trying to browse to / mounting a React app using PathPrefix and Index
Code snippet
Result:
Cannot GET /
Browsing to http://localhost:3000/index.html directly works fine.
The text was updated successfully, but these errors were encountered: