'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:
- Keep the current URL the user is on
- Display
error.html - Have the asset paths in
error.htmlbe correct?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
