Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

413
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda