Page MenuHomePhabricator

[deployment][Dashboard][Leaderboard] Page refresh results in 404 error
Closed, ResolvedPublicBUG REPORT

Description

Trying to refresh the page while on the Dashboard or Leaderboard will result in a 404 error.

This is only a problem on Toolforge.

Event Timeline

NicoleLBee changed the task status from Open to In Progress.Apr 11 2023, 6:09 AM
NicoleLBee claimed this task.
NicoleLBee moved this task from Backlog to In review on the Toolhunt board.

The issue was in the[[ https://router.vuejs.org/guide/essentials/history-mode.html | history mode ]] that we were using with the Vue router. (In development it appears that Vite was taking care of this for us... in production, not so much.) By switching to WebHashHistory mode I've enabled reloads on production. The downsides are that the URLs are now kind of ugly and apparently this is bad for SEO, if we even care about such things.

It would probably be possible to set up some sort of configuration whereby we could reenable WebHistory mode, but it might involve just redirecting all requests back to the index page, but I'd have to dig a little deeper into that. This works for now.

PR open at https://github.com/wikimedia/toolhunt-ui/pull/60

It would probably be possible to set up some sort of configuration whereby we could reenable WebHistory mode, but it might involve just redirecting all requests back to the index page, but I'd have to dig a little deeper into that. This works for now.

In Toolhub we setup backend routes that match the potential front-end routes and make all of those backend routes serve up the frontend application. See https://gerrit.wikimedia.org/r/plugins/gitiles/wikimedia/toolhub/+/767467821b81f549ec4572a9b5bc4bebde4b9b05/vue/urls.py and https://gerrit.wikimedia.org/r/plugins/gitiles/wikimedia/toolhub/+/767467821b81f549ec4572a9b5bc4bebde4b9b05/toolhub/urls.py#58. This makes it so that a hard refresh or a deep link that you otherwise follow will hit the backend which will then serve up the SPA for the frontend. When the SPA initializes its internal router will then figure out which client side code to run to render the result.

For toolhunt where you are using an express app rather than Django as your content serving backend, I think that you could do something like this as the last middleware in your server.js file:

app.use( function( req, res ) {
    req.url = "/index.html";
    app.handle( req, res );
} );

This config basically makes your /index.html route the default 404 response, but does so using internal redirects so that the client does not get a 3xx response. If you do this your frontend should also include some reasonable 404 handler so that end users are eventually notified when they load a truly not-found URL.

Alternately, you could add a distinct app.use( "/url/goes/here", ... ); for each URL pattern like Toolhub does.