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

122
Views
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
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!