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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤔 app.Static serving JS as text/plain #352

Closed
fhammoud opened this issue May 9, 2020 · 5 comments
Closed

🤔 app.Static serving JS as text/plain #352

fhammoud opened this issue May 9, 2020 · 5 comments
Assignees

Comments

@fhammoud
Copy link

fhammoud commented May 9, 2020

Question description
I'm not sure if this is a bug or if I'm doing this wrong, but I created an Angular 9 app to be served by my Fiber app. The Angular app compiles the output to /public. When I add the app.Static middleware I can see that all my angular files have been sent but the JS files have the mime-type text/plain instead of application/javascript, and so the browser is throwing an error: "Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec."

Code snippet (optional)

package main

import (
	"fmt"
	"github.com/gofiber/fiber"
	"github.com/gofiber/logger"

	"fiber/api/car"
)

func main() {
        app := fiber.New()

        // Add middleware
	app.Use(logger.New())

	// Serve static files
	app.Static("/", "./public")

	// Setup routes
	car.Routes(app)

	// Start Fiber server
	err := app.Listen(8080)
	if err != nil {
		fmt.Print("Failed to start server")
	}
}
@welcome
Copy link

welcome bot commented May 9, 2020

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

@Fenny
Copy link
Member

Fenny commented May 10, 2020

@fhammoud, what OS are you running on and do the javascript files have the .js extension?

@fhammoud
Copy link
Author

fhammoud commented May 10, 2020

I'm on Windows 10, and yes they do have .js extension. They're the typical Angular app files if you're familiar with Angular. However, the CSS file has the correct type of text/css.
image

@fhammoud
Copy link
Author

@thomasvvugt Helped me with this. The issue was wrong Content Type defined for .js in the Windows registry.
In case anyone else sees this, open regedit, go to HKEY_LOCAL_MACHINE > SOFTWARE > Classes > .js (or any other file extension you need). Then modify the Content Type field.

@thomasvvugt
Copy link
Contributor

Issue is open on Go itself as well.
See golang/go#32350

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

No branches or pull requests

5 participants