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

132
Visualizações
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 à 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