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

213
Views
Enrutamiento desde cualquier ruta a los mismos archivos en express, nodejs

Quiero poder enviar los mismos archivos por diferentes rutas como /stuff y /stuff/foo, el problema es que cuando intento hacer esto, aparece el siguiente error:

 Refused to execute script from 'http://localhost:8000/stuff/main.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

Aquí está el código:

 app.use("/", express.static(path.join(__dirname, "./../public"))); app.get("/stuff", sendIndexHTML); app.get("/stuff/:id", sendIndexHTML); function sendIndexHTML(req, res) { res.sendFile(path.join(__dirname + "./../public/index.html")); }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Está haciendo referencia a main.js en su index.html como una ruta relativa, por lo que se sirve desde /stuff , que esa ruta está configurada para devolver index.html (que tiene un tipo de mime text/html ).

Lo que debe hacer es actualizar la ruta del archivo de script en su archivo html.

cambio

 <script src="main.js"></script>

a

 <script src="/main.js"></script>

de esa manera, se sirve desde la ruta raíz que está configurada para servir activos estáticos.

over 4 years ago · Santiago Trujillo Report
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!