Sometimes, when a request for a page fails, it would be good to have enough context about the user's navigation through the site to know where we should bounce/redirect them to.
Solution:
This is simple enough to hand-roll. Basically, we need a piece of middleware that piggy-backs off of the 'Session' middleware. It'll store a URL in the req.session object (say in req.session.previousPage) so that whenever the server wants to redirect the user to the 'last page' they were on, the server can just redirect the user to this URL.
One slight complication is to figure out which routes/requests actually count as "pages" that we could redirect the user back to.
Problem:
Solution: