Skip to content

feat(seo): ✨ site indexing, robots.txt and sitemaps from server config - #937

Merged
aXenDeveloper merged 1 commit into
canaryfrom
claude/vitnode-seo-robots-sitemaps-9d0doc
Nov 29, 2026
Merged

aXenDeveloper merged 1 commit into
canaryfrom
claude/vitnode-seo-robots-sitemaps-9d0doc

Conversation

@aXenDeveloper

Copy link
Copy Markdown
Owner

Improving Documentation

  • Ran pnpm lint:fix-equivalent checks (oxlint --type-aware per package, root oxfmt --check) before opening the PR.
  • Followed the Docs Contribution Guide.

Description

What?

Core (@vitnode/core, @vitnode/api)

  • buildServerConfig({ seo }), an optional, typed contract documented in JSDoc. Leaving seo out keeps the current behavior: requests pass through untouched, so apps that serve their own robots or sitemap files keep them. Once seo is set, indexing is required. The sitemap defaults to indexing, indexing: false turns the sitemap off whatever else is set, and any crawler left out follows User-agent: *. Static paths are validated as canonical, unlocalized paths, normalized and deduplicated.
  • withSeo / createSeoHandler in @vitnode/core/tanstack/seo/server, composed outside withPageCache:
    • /robots.txt is built from config only: no API, session or database. It has a User-agent: * group with /admin and the account settings path excluded for every locale (translated routePaths included). It adds a group for each configured bot: OAI-SearchBot/GPTBot, Claude-SearchBot/ClaudeBot and Google-Extended. A bot set to false gets Disallow: /; a bot set to true gets the baseline exclusions repeated. There is exactly one absolute Sitemap: line, and HEAD returns the same headers with no body.
    • indexing: false adds X-Robots-Tag: noindex to HTML responses, including page-cache HITs, and keeps any directive already on the response. Prerendered documents also get <meta name="robots" content="noindex"/>. Sitemap routes return 404.
    • /sitemap.xml is an index of root-level child files, /sitemap-{file}-{n}.xml. They come from three sources: seo.sitemap.paths (each locale with hreflang alternates and x-default), app list sources, and every content type with delivery.sitemap. Content records are read from the existing /delivery/sitemap routes through a new guestRawFetcher, which sends no cookies, authorization or forwarded visitor headers. It calls the API in process for single-app deployments (falling back to the app's own server entry until the /api route module has loaded) and over the network for a separate API. nextCursor is treated as opaque.
    • URLs only ever come from VITNODE_WEB_URL or a configured i18n.domains origin. Each host's sitemap lists only that host's URLs. A request's Host or forwarding headers only choose among the configured origins.
  • Caching. Generated XML lives in the page cache's existing store: Redis when configured, otherwise in process. When the page cache is off, the store is registered so invalidations still reach the sitemaps.
    • Cache keys include the build revision, host, file and part.
    • Each content file is a generation. A request reads at most 8 API pages, and a background waitUntil run continues an unfinished build. A generation's part list is published only after every part is stored.
    • A child request reads its part straight from the published part list. If that part was evicted, it re-reads only that part's start cursor and checks the end cursor.
    • The index records the generation of every file it lists (10-minute TTL vs 1 hour for children), so it never lists a file from a different generation.
    • If an invalidation lands after a generation started, that generation is never published.
    • After a hard invalidation, old XML is never served again. If no valid copy exists, the response is 503 with Retry-After and is not cached.
    • Responses use cache-control: no-cache with an ETag, so removals reach the public at once.
  • Invalidation. invalidateContentPages now also expires contentDeliverySitemapTag for the content type and its dependents. Toggling a record's noIndexField is escalated to a hard invalidation. There was no revalidation receiver anywhere, so withSeo now answers POST /api/vitnode/content/revalidate. It checks the bearer CRON_SECRET in constant time, rejects stale timestamps, and expires only the sitemap tags.
  • Vite plugin. The existing discovery in plugin-routes.ts now also writes src/sitemap-sources.gen.ts. It reuses the content definitions the public-URL check already loaded, keeps types with public API + delivery + delivery.sitemap, records plugin id, type id, endpoint and localization, and fails the build on file-name collisions. The build warns when public/robots.txt or public/sitemap*.xml would shadow the generated files.
  • contentSitemapXml accepts entries without lastModified (the new ContentSitemapXmlEntry type). The ContentSitemapEntry API contract is unchanged.

Starter: server.ts composes withSeo. vitnode.server.config.ts sets seo: { indexing: process.env.VITNODE_SEO_INDEXING === "true", sitemap: { paths: ["/"] } }, so new sites are not indexable until opted in. VITNODE_SEO_INDEXING is added to the env examples, the monorepo turbo.json build env, and Docker compose.

vitnode.com (apps/web):

  • Site SEO is enabled. Indexing is on only when VITNODE_WEB_URL is https://vitnode.com, so previews answer noindex.
  • sitemap.paths reuses PRERENDERED_PATHS.
  • Docs come from a Fumadocs list source (src/docs/sitemap.server.ts).
  • The legacy public/robots.txt and public/sitemap.xml are removed.
  • The crawler policy is unchanged: no bot groups, the same /admin and /settings exclusions, plus /pl/settings. Maintainers can opt in to seo.crawlers explicitly.
  • Old vs new sitemap: 14 of 15 legacy URLs are listed as-is. /docs/dev/content-engine now 301-redirects to /docs/content-engine, which is listed. Polish variants of the marketing pages are added because they are canonical.

Docs:

  • New dev/seo.mdx, registered in dev/meta.json. It covers the smallest config, options and defaults, the robots output, bot controls, production vs preview, sitemap sources, freshness, and migration/verification with curl, prerendered HTML and Cloudflare's managed robots.txt.
  • dev/configuration.mdx lists seo and the new generated file.
  • content-engine/seo.mdx now leads with automatic discovery through delivery.sitemap and shows how to check that a published record appears and a noindex record disappears. Manual XML assembly is kept as the advanced path.

Why?

Maintainers need deployment-time control over search indexing, sitemap publication and AI crawlers without hand-maintained static files. Plugin authors now only declare delivery.sitemap.

Checks run

  • packages/vitnode: tsc --noEmit, oxlint --type-aware and pnpm test:unit all pass: 359 files, 4,668 tests, including 150 new SEO/sitemap tests.
  • packages/api: oxlint --type-aware and pnpm test:unit pass: 336 files, 6,143 tests, including new sitemap and page-cache cases. A test-only mutation pass (6 deliberate engine breakages, then reverted) confirmed at least one test fails for each.
  • apps/web: tsc --noEmit, oxlint and node --test pass. The Node build and the Cloudflare build (pnpm build:cloudflare) both succeed. create-vitnode-app vitest: 135 tests pass. Root oxfmt --check passes.
  • Node smoke (built apps/web with a local Postgres):
    • robots.txt is correct and stays on the configured origin when sent a forged Host/X-Forwarded-Host.
    • The index and its children return 200.
    • The published record and its published translation are listed. The draft, hidden record, unpublished translation and noIndex: true record are not.
    • The revalidation receiver returns 403 for a wrong bearer or stale timestamp, 400 for a bad body, and 204 on success, after which the files refresh.
    • ETag/304, HEAD and invalid child paths return 404 as expected.
    • With indexing off: fresh SSR and page-cache HITs carry X-Robots-Tag: noindex, prerendered files carry the robots meta, and sitemaps return 404.
  • Cloudflare smoke (wrangler dev on the built Worker):
    • Indexing off: robots.txt comes from the Worker, the sitemap returns 404, and the assets-served prerendered / has the meta tag. SSR MISS and HIT responses both carry X-Robots-Tag.
    • Indexing on: process.env is populated at module load in workerd, the Sitemap: line is present, and the sitemap is built in process inside the Worker.
  • Starter smoke: a freshly generated single app builds. With no reachable Postgres it still serves robots.txt and its static sitemap.

Not run: the 50 MB byte-split path has no test, because reaching it needs very large data. GitHub CI has not been inspected yet. Turbo-driven pnpm lint/pnpm test could not spawn tasks in this sandbox, so each package's scripts were run directly instead.


Generated by Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T14:07:32.313830Z a751f91 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the 💡 Feature A new feature label Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit a751f91.

@aXenDeveloper
aXenDeveloper force-pushed the claude/vitnode-seo-robots-sitemaps-9d0doc branch 2 times, most recently from 72b3f6e to 6f3e37e Compare November 29, 2026 14:02
Add an optional `seo` block to `buildServerConfig` and a `withSeo` server handler (`@vitnode/core/tanstack/seo/server`) composed outside `withPageCache`:

- `/robots.txt` from config alone, with the AdminCP and account-settings exclusions in every locale and per-bot groups for OAI-SearchBot, GPTBot, Claude-SearchBot, ClaudeBot and Google-Extended.
- `indexing: false` adds `X-Robots-Tag: noindex` to HTML (cache hits too) and a robots meta to prerendered pages; sitemaps answer 404.
- `/sitemap.xml` index with root-level child files from `seo.sitemap.paths`, app list sources and every content type with `delivery.sitemap`, read as a guest through the delivery routes.
- Generated XML cached in the page cache store, built incrementally per content file and expired by content writes (hard on removals and noindex toggles) and by the content revalidation receiver.
- The Vite plugin writes `src/sitemap-sources.gen.ts` and warns about static robots/sitemap files that would shadow the generated ones.
- Regression tests for robots, indexing, sitemaps, revalidation and sitemap sources.
- Migrate vitnode.com and the starter, remove legacy static files, and document SEO and social images.
@aXenDeveloper
aXenDeveloper force-pushed the claude/vitnode-seo-robots-sitemaps-9d0doc branch from 6f3e37e to a751f91 Compare November 29, 2026 14:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a751f91a69

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +241 to +244
// write, so a record that left the public site leaves its sitemap too.
const sitemapMode = noIndexChanged(definition, payload) ? "hard" : mode;
const sitemapTags = [definition, ...dependents].flatMap(target =>
contentSitemapPageCacheTags(target),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Relay sitemap invalidations for ordinary API writes

In a split API/web deployment using separate memory stores, these tag invalidations affect only the API process, even when content.revalidateOrigins is configured. Ordinary edits, deletes and manual publication changes reach invalidateContentPages through emitContentEvent, but the only callers of dispatchContentRevalidation are schedule-effects.ts and visibility-effects.ts. Consequently, deleting a record or setting its noindex field leaves its URL in the frontend's cached sitemap until the periodic refresh; the new revalidation receiver never hears about the change. Relay these mutations to the configured frontend origins as well, preserving hard invalidation for removals.

AGENTS.md reference: AGENTS.md:L103-L103

Useful? React with 👍 / 👎.

@aXenDeveloper
aXenDeveloper merged commit ecb2c67 into canary Nov 29, 2026
7 checks passed
@aXenDeveloper
aXenDeveloper deleted the claude/vitnode-seo-robots-sitemaps-9d0doc branch November 29, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💡 Feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant