Don't redirect errors to /wp-json/ #126
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.