E
E
EyesPain2021-04-24 11:21:40
go
EyesPain, 2021-04-24 11:21:40

golang. Failed to load module script. How to fix?

JS files come with incorrect content-type, although in the header I specify application/javascript

6083d403053b5463437284.png

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))
}


Error name:
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

1 answer(s)
F
falconandy, 2021-04-24
@EyesPain

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 question

Ask a Question

731 491 924 answers to any question