Skip to Content
Documentation

SEO

Set up SEO

Turn on VitNode's generated robots.txt, sitemap and noindex handling with the withSeo server entry, and change the defaults with the seo block.

VitNode can serve your site's /robots.txt, a /sitemap.xml index and a deployment-wide noindex. This page turns them on. Each feature then has its own guide.

The defaults need no config: once the server entry is wrapped with withSeo, the site is indexable, robots.txt keeps crawlers out of private areas and the sitemap lists your content. Apps created with create-vitnode-app already wrap it.

Wrap the server entry with withSeo

withSeo from @vitnode/core/tanstack/seo/server goes outside withPageCache in src/server.ts, so pages served from the page cache get the same policy as fresh renders:

src/server.ts
import handler from '@tanstack/react-start/server-entry'
import { withPageCache } from '@vitnode/core/tanstack/page-cache/server'
import { withSeo } from '@vitnode/core/tanstack/seo/server'

import { pageCacheBuildId, pageCacheRoutes } from '@/page-cache.gen'
import { sitemapManifest } from '@/sitemap-sources.gen'
import { vitNodeConfig } from '@/vitnode.config'
import { vitNodeServerConfig } from '@/vitnode.server.config'

export default withSeo(
  withPageCache(handler, {
    buildId: pageCacheBuildId,
    config: vitNodeConfig,
    routes: pageCacheRoutes,
  }),
  { config: vitNodeServerConfig, sitemap: sitemapManifest },
)

VitNode's Vite plugin writes src/sitemap-sources.gen.ts on every vitnode dev and vitnode build, like the other *.gen.ts files. It lists the content types whose records go into the sitemap.

Remove static robots and sitemap files

Delete public/robots.txt and any public/sitemap*.xml. Hosts serve files from public/ before your server runs, so those files would replace the generated ones. The build prints a warning while one is still there.

Change the defaults (optional)

Leaving seo out of buildServerConfig is the same as seo: { indexing: true }. Add the block in src/vitnode.server.config.ts only to change something, such as your own sitemap pages or the AI crawler rules:

src/vitnode.server.config.ts
import '@tanstack/react-start/server-only'
import { buildServerConfig } from '@vitnode/core/vitnode.config'

import { appMessages } from '@/locales/app'
import { packageMessages } from '@/package-messages.gen'
import { vitNodeConfig } from '@/vitnode.config'

export const vitNodeServerConfig = buildServerConfig({
  config: vitNodeConfig,
  messages: appMessages,
  packageMessages,
  seo: {
    sitemap: { paths: ['/', '/about'] },
  },
})

Set indexing: false on preview and staging deployments, so they stay out of search results. Indexing shows how to pick the value per deployment.

To serve your own robots.txt and sitemap instead, leave withSeo out of src/server.ts.

Which origin URLs use

Every URL VitNode writes uses VITNODE_WEB_URL, or a language's own origin from i18n.domains when the request is for that host. The request's Host header only picks between those configured origins, so nobody can make your sitemap point at another domain.

Set VITNODE_WEB_URL to the public origin wherever the server runs. Without it, URLs fall back to http://localhost:3000.

Check the result

Start the app and request the generated file:

curl -i http://localhost:3000/robots.txt

Expect 200, content-type: text/plain; charset=utf-8 and exactly one Sitemap: line with your origin. robots.txt explains every line.

The config is read when the server starts, so a change takes effect with the next restart or deployment.