Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

407
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!