fix(seo): allow public api crawling in robots.txt and add X-Robots-Tag noindex - #96
Merged
Merged
Conversation
…g noindex - Allow /api/ in robots.txt while keeping /api/admin/ disallowed so Googlebot can render SPA content - Add X-Robots-Tag: noindex header to all JSON API responses to prevent indexing raw endpoints - Align homepage preload query parameter to /api/news?page=1&page_size=16 to prevent unused preload warnings
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.
Bug Description & Symptom
Google Search Console reported
https://neuralwire.info/as "Halaman tidak dapat diindeks: Soft 404". Furthermore, GSC page asset inspection reported 4 assets blocked by robots.txt (/api/categories,/api/news/trending?window=week&limit=10,/api/news?page=1&page_size=16,/api/news?page_size=16), and console warnings indicated that/api/news?page_size=16was preloaded via link preload but never consumed.Root Cause Analysis
backend/internal/api/handlers.goexplicitly hadDisallow: /api/inrobots.txt. Because SvelteKit client renders news articles dynamically by fetching public API endpoints, Googlebot's crawler refused to fetch any/api/endpoints due to the robots.txt directive. This caused the SPA client rendering to fail with 0 articles, rendering an empty page which Google's heuristic classified as a Soft 404.backend/internal/api/server.go, the preload link inserveIndexHTMLwas<link rel="preload" as="fetch" href="/api/news?page_size=16">whereas SvelteKit'sgetNewsPagerequested/api/news?page=1&page_size=16. The query string mismatch caused Chrome/Googlebot to flag the preload as unused.Proposed Fix
robots.txtinhandlers.goto disallow/api/admin/while explicitly allowing/api/(Allow: /api/). This allows crawlers to fetch public news/category endpoints for page rendering while keeping administrative endpoints protected.X-Robots-Tag: noindexinwriteJSON()(server.go). This ensures crawlers never index raw JSON endpoints as search results, but can fetch them during page rendering.server.goto/api/news?page=1&page_size=16to match frontend SvelteKit requests.handlers_test.goto verifyAllow: /api/,Disallow: /api/admin/, and the updated preload link.Scope Lock & Blast Radius
Mandatory Zero-Failure Pre-Commit Verification (AGENTS.md)
All commands below must be executed locally and pass with Exit Code 0 prior to creating the PR:
Backend Suite (if backend code changed)
gofmt -w . && gofmt -l .(Output must be completely empty)go vet ./...(Static analysis clean)go test -count=1 -v ./...(All tests pass with cache disabled)Frontend Suite (if frontend code changed)
npm run format && npm run lint(Prettier code style & ESLint clean)npm run check(SvelteKit TypeScript validation clean)npm run build(Production build succeeds with static adapter)Live Localhost End-to-End (E2E) Verification (Mandatory)
go run ./cmd/server/ preview) with 0 startup crashes/panics.Local Verification Evidence