Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

409
Visualizações
How can I set correct http.FileServer mime types?

Is there any way to overwrite the content-type used in FileServer? I have simple REST server written in golang, and now i want add some "frontend" in Vue.

Html/js files are served from /static/ folder and almost everything works fine...

Almost, except Vue files.

My /static/ is served by:

fs := http.FileServer(http.Dir("./static/"))
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs))

all *.vue files are served with Content-Type: text/plain; charset=utf-8, and all browsers throws error:

Failed to load module script:
Expected a JavaScript module script but the server responded with a MIME type of "text/plain". 
Strict MIME type checking is enforced for module scripts per HTML spec.

How overwrite this Content-type? Maybe something like Handler.extension_map in python?

I tried:

log.Println(mime.TypeByExtension(".vue"))
mime.AddExtensionType(".vue", "application/javascript")
log.Println(mime.TypeByExtension(".vue"))
// Returns:
// 2022/01/14 11:45:50 
// 2022/01/14 11:45:50 application/javascript

Which works fine itself, but is apparently ignored by FileServer.

Alternatively, how else to solve this problem?

P.S. Yes, i saw: http.FileServer response with wrong mime "Content-Type" But didn't help in my case.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda