fix(site): restore docs-sitemap.xml#3821
Merged
Merged
Conversation
…KEN) Production was returning 500 for /docs-sitemap.xml because the deploy env has a revoked or invalid GITHUB_TOKEN. Octokit was sending it on every request, GitHub replied "Bad credentials" (401), the exception bubbled out of getServerSideProps, and Next rendered the error page. Two layers of defense: 1. parse-mdx-docs.ts: only pass `auth` to Octokit when the token is a non-empty trimmed string. A missing/blank/invalid-because-empty token now falls back to unauthenticated GitHub requests (60 req/hr, plenty for a sitemap and dev-time doc fetches). Removing the env var entirely is now a clean way to recover from a bad token. 2. docs-sitemap.xml.ts: wrap getAllDocUri() in try/catch. If anything in the GitHub chain still fails at runtime (rate-limit, network, downstream API change), log the error and emit a valid empty <urlset> rather than 500. Verified locally: with no token, the sitemap populates with 51 real doc URIs. With an invalid token, it returns 200 with an empty but well-formed sitemap, and the error is logged to the server. To populate the production sitemap, either set a valid read-only PAT on GITHUB_TOKEN in the deploy env, or unset it to use unauth requests.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
https://www.wpgraphql.com/docs-sitemap.xml was returning 500 Internal Server Error in production. Reproduced locally and confirmed the cause: the deploy env's GITHUB_TOKEN is invalid (revoked / expired), so Octokit's call to GitHub's contents API in
getAllDocMeta()returns 401 Bad credentials, the exception bubbles out ofgetServerSideProps, and Next renders the error page.Fix
src/lib/parse-mdx-docs.ts: only pass auth to Octokit whenGITHUB_TOKENis a non-empty trimmed string. A missing or blank token now falls back to unauthenticated GitHub requests (60 req/hr plenty for an SSR sitemap and dev-time doc fetches). Previously, a blank token was still passed and produced the same 401 a revoked token produces.src/pages/docs-sitemap.xml.ts: wrapgetAllDocUri()in a try/catch. If anything in the GitHub chain still fails (rate limit, network, downstream API change), log the error and emit a valid empty instead of crashing.Test plan
<urlset>(invalid token), error logged to server