Fix Googlebot robots.txt blocking of public read-only API endpoints#165
Merged
Conversation
The public server's robots.txt had a blanket Disallow: /api/, which blocked Googlebot from fetching the JSON the public site hydrates from. JS-rendering crawlers that can't load /api/* fall back to the SSR shell and skip the second render pass, hurting indexing. The public server only exposes GET-only, rate-limited, sensitive-field- filtered endpoints by design, so emit explicit Allow: rules for each public read-only API path before the trailing Disallow: /api/ — the longest-prefix-wins rule keeps anything not on the allow-list blocked. Extracted a shared buildRobotsTxt(req) helper so the dual-server and PUBLIC_ONLY robots.txt handlers can't drift apart.
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.
Description
Googlebot was reporting
Blocked by robots.txtfor public read-only API endpoints (e.g./api/datasets/id/:id,/api/settings/language). The public site hydrates client-side from/api/*JSON endpoints, so when a JS-rendering crawler can't fetch those endpoints, it sees only the SSR shell and skips re-render — degrading indexing quality.The public server's
robots.txtpreviously had a blanketDisallow: /api/, which blocked all API access. However, the public server only ever exposes a curated set of GET-only, rate-limited, sensitive-field-filtered endpoints, so it's safe to expose those to crawlers.This PR updates
robots.txtto emit explicitAllow:rules for each public read-only API path before the trailingDisallow: /api/. Per Google's robots.txt spec, the longest-prefix-wins rule ensures anything not on the allow-list stays blocked by default.Changes
PUBLIC_API_ALLOW_PATHSconstant listing all safe public API endpointsbuildRobotsTxt(req)helper function to unify bothrobots.txthandlers (dual-server and PUBLIC_ONLY paths) so they can't driftrobots.txtoutput to include explicitAllow:rules for:/api/profile,/api/sections,/api/settings,/api/experiences,/api/certifications,/api/education,/api/skills,/api/projects,/api/timeline,/api/custom-sections,/api/layout-types,/api/social-platforms,/api/cv,/api/datasets/slug/,/api/datasets/id/noindexbranchesType of Change
Checklist
Required for all code changes
npm testpasses)package.json,package-lock.json,version.json)CHANGELOG.mdhas been updated with a new entry under the correct versionIf adding or changing user-visible strings
If documentation-only change
Test Plan
Added two new test cases in
tests/backend.test.js:Allow:rules inrobots.txtwhenrobotsMetais set to indexrobots.txtemits a globalDisallow: /whenrobotsMetais set tonoindexBoth handlers (dual-server and PUBLIC_ONLY) now share the same
buildRobotsTxt()function, eliminating the risk of divergence.https://claude.ai/code/session_01EahTJ7kaq3g5ze6F3MmNn6