Answer the question
In order to leave comments, you need to log in
golang. Failed to load module script. How to fix?
JS files come with incorrect content-type
, although in the header I specify application/javascript
the Header setup code
func JSHeader(c *gin.Context) {
c.Writer.Header().Add("Content-Type", "application/javascript")
}
//Start Запускает сервер
func Start() {
r := gin.New()
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return origin == "*"
},
MaxAge: 12 * time.Hour,
}))
r.Static("/css", "ui/css")
r.Static("/js", "ui/js")
r.Static("/ico", "ico")
r.LoadHTMLGlob("ui/*.html")
r.HEAD("/js", JSHeader)
r.GET("/", indexHandler)
//Server run
r.Run(fmt.Sprintf("%s:%s", conf.Server.Host, conf.Server.Port))
}
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.
Answer the question
In order to leave comments, you need to log in
https://github.com/gin-gonic/gin/issues/1595
https://github.com/labstack/echo/issues/1038#issue...
And the code with the explicit setting of the header to HEAD can be thrown away.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question