-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🤗 [Question]: app.Static(...) function sends content-type "text/plain" instead of "application/javascript" #2659
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 |
I think the issue came from fasthttp https://github.com/valyala/fasthttp/blob/master/fs.go#L1324 func (h *fsHandler) newFSFile(f *os.File, fileInfo os.FileInfo, compressed bool, fileEncoding string) (*fsFile, error) {
...
// detect content-type
ext := fileExtension(fileInfo.Name(), compressed, h.compressedFileSuffixes[fileEncoding])
contentType := mime.TypeByExtension(ext)
if len(contentType) == 0 {
data, err := readFileHeader(f, compressed, fileEncoding)
if err != nil {
return nil, fmt.Errorf("cannot read header of the file %q: %w", f.Name(), err)
}
contentType = http.DetectContentType(data) // this probably is reading data and setting the wrong content type you can test local if your system can recognize the extension .jsx package main
import (
"fmt"
"mime"
)
func main() {
fmt.Println("jsx", mime.TypeByExtension(".jsx"))
fmt.Println("js", mime.TypeByExtension(".js"))
} if not, you have two options:
enjoy |
this problem has been documented many times and is due to the golang version and or operation system check this |
Thanks for your helps @peczenyj your solution work but the browser can't read jsx file and it got syntax error @ReneWerner87 i'm not have windows but i searched to add jsx type to linux mime database but i can't do it. Thanks |
since you have found the solution, i will close the issue |
Question Description
hello
i work in project with gofiber and react
when i serve the static files with app.Static("...", "...") the browser send request for main.jsx file and server send response, the problem is server should send content-type "application/javascript" and instead of it, server send "text/plain", and browser block the file after file received.
how can i fix it.
Code Snippet (optional)
No response
Checklist:
The text was updated successfully, but these errors were encountered: