However, this caused issues because when there was just an error on the page with rendering an article (which has nothing to do with the REST API), it would also redirect to /wp-json/ and become cached, so users would commonly just see code when going to our site.
This PR changes that approach by:
Using the default error page, so users will just see a "404 not found" or some error like that instead of being redirected to code.
Reasons for making this change
Previously, we had redirected all errors on the stanford daily page to https://wp.stanforddaily.com/wp-json/. This is because in order for the REST API to work, we need to redirect all paths from https://stanforddaily.com/wp-json/... to their corresponding https://wp.stanforddaily.com/wp-json/... paths.
However, this caused issues because when there was just an error on the page with rendering an article (which has nothing to do with the REST API), it would also redirect to /wp-json/ and become cached, so users would commonly just see code when going to our site.
This PR changes that approach by:
[...slug].tsx
feature of Next.js, which allows us to redirect an arbitrarily-long path after https://stanforddaily.com/wp-json/... to https://wp.stanforddaily.com/wp-json/... . (see this page for more information: https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes)Testing
http://localhost:3000/wp-json/tsd/json/v1/tag/coronavirus/1 should redirect to https://wp.stanforddaily.com/wp-json/tsd/json/v1/tag/coronavirus/1.