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

124
Vistas
ExpressJS redirection/sendFile with assets

In the express server, we have a catch-all for rendering errors that looks like this:

res.status(500).sendFile('error.html', { root: path.join(__dirname, '../public') });

Which will send the user to a "404"-looking HTML page, while setting the status to 500 (for application insights filtering for these types of errors).

However, it seems like using sendFile keeps the same URL that the user is currently at, while displaying error.html. This is a problem, since we use relative paths in error.html (i.e., ./icons/logo.png).

Since sendFile keeps the same path for the user, it then looks at a URL like site.com/some/path/the/user/is/at/icons/logo.png instead of site.com/icons/logo.png.

So, how can I:

  1. Keep the current URL the user is on
  2. Display error.html
  3. Have the asset paths in error.html be correct?
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