Using Fiber v1.10.1
Question description
I'm not sure if this is a bug or I understood it wrong.
It seems the root route must be defined first of all routes, otherwise its content will be rendered as plain text.
Code snippet (optional)
This will result in index.html, at /, being rendered as text/plain:
package main
import "github.com/gofiber/fiber"
func main() {
app := fiber.New()
app.Static("/otherPath", otherPath) // I'm using here an absolute path
app.Static("/", "./public")
app.Listen(8000)
}
This will result in index.html, at /, being rendered as text/html:
package main
import "github.com/gofiber/fiber"
func main() {
app := fiber.New()
app.Static("/", "./public")
app.Static("/otherPath", otherPath)
app.Listen(8000)
}
Of course, this is not a big deal. It's customary to put the root first most of the time, but even so I just don't know, is this intended behavior or...?
Thanks for your time!
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
@soulchainer I couldn't produce the same result, by any chance you are using Windows? Because it could be caused by a specific windows update that changed the MIME types in the registry.
@thomasvvugt do you remember how you solved this issue?
To make sure it's OS related I added an additional test case https://github.com/gofiber/fiber/pull/421
@Fenny No, I'm using Arch Linux.
And is neither a browser issue (checked in Firefox/Firefox developer edition/Chromium, the browsers I usually use).
Fiber v1.10.1
go version go1.14.3 linux/amd64
Linux 5.6.4-arch1-1
Could you try to run this test app_test.go#L208 on your machine (there is an index.html test file in ./github)
Could you also share the <html>, <head> content of your index.html file?
@Fenny That test runs OK, because it doesn't cover this case, but only the case where it already works.
As I said, if you have app.Static("/", "./.github") appearing first in your code, it works fine (the case you're checking in your test).
If you edit that test adding the extra line that I add below, which covers this error case:
func Test_App_Static_Index(t *testing.T) {
app := New()
// I added this line, some folder in your machine, obviosly this should be some other general file, quick check for my case
app.Static("/music", "/home/soulchainer/Music")
app.Static("/", "./.github")
req := httptest.NewRequest("GET", "/", nil)
resp, err := app.Test(req)
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
utils.AssertEqual(t, false, resp.Header.Get("Content-Length") == "")
utils.AssertEqual(t, "text/html; charset=utf-8", resp.Header.Get("Content-Type"))
body, err := ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, strings.Contains(string(body), "Hello, World!"))
}
It fails like this:
--- FAIL: Test_App_Static_Index (0.00s)
utils.go:169:
Test: Test_App_Static_Index
Trace: app_test.go:219
Error: Not equal
Expect: text/html; charset=utf-8 [string]
Result: text/plain; charset=utf-8 [string]
FAIL
FAIL github.com/gofiber/fiber 0.008s
FAIL
Which is what I said is happening.
My current index.html file is almost the same that the one you wrote here, because I was just trying Fiber and it was an Hello world. Is this:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cliente</title>
</head>
<body>
Hello world!
</body>
</html>
Thank you for your detailed bug report, I will debug this today and keep you posted 馃憤
am also interested in this bug as I noticed the same behavior in one of our microservices, had debugged it before and was able to trace it back to fasthttp, where the default content type is used
Take a closer look tomorrow
The content-type issue has been fixed in v1.10.2
Thank you for your issue 馃憤