Next.js Strapi Sitemap & Robots.txt Generator is an open-source Node.js script that produces sitemap.xml and robots.txt for Next.js websites, refreshed automatically by Strapi webhooks and at build time. It is a small utility that lives in a scripts folder of a Next.js project and listens for content changes in Strapi CMS to keep search engine files current.
What is this generator?
The generator is a Node.js script that reads configuration from a .env file (PORT, HOST, BACKEND_HOST, WEBHOOK_TOKEN) and outputs sitemap files into a subfolder of the public directory plus a robots.txt at the root. It was authored by GitHub user stovv and has 6 stars on the repository stovv/next-strapi-sitemap. The tool is designed specifically for projects that use Next.js with Strapi as a headless CMS, and it runs on a Node server alongside next start.
Key Features
- Webhook-triggered regeneration — After you configure a Strapi webhook with an Authorization header containing your WEBHOOK_TOKEN, every create, update, or delete action on Strapi entries triggers the generator to rewrite sitemaps immediately.
- Build-time generation — By calling the
generatefunction fromnext.config.jsinside the webpack server build hook, the script generates sitemaps and robots.txt on everynext build, so production deployments always start with fresh files. - Multiple sitemap output — Generated sitemaps go into a configurable subfolder such as
sitemapsunder the public folder, while the index sitemap stays at the public root. - robots.txt disallow rules — You can pass an array of routes to disallow, for example
/api/and/login, and the generator writes those rules into robots.txt. - Environment-based setup — All connection details come from a .env file, including PORT, HOST, BACKEND_HOST, and WEBHOOK_TOKEN, keeping secrets out of code.
- Simple start command integration — The recommended install updates package.json so the generator runs automatically when the Next.js app starts via
yarn startornpm run start.
Who is it for?
This generator is for Next.js developers who build sites on Strapi and want sitemaps that stay in sync with content without manual rebuilds. It also suits SEO-focused teams that need to exclude private paths like /api/ and /login from robots.txt and prefer to have sitemaps ready at build time rather than generated at runtime.
What can you do with it?
- Content editors on Strapi: Publish a new blog post and the generator immediately updates the sitemap through the webhook, making the page discoverable by search engines sooner.
- Next.js deploy maintainers: Set the generator to run in next.config.js so every production build ships a current sitemap index and robots.txt.
- SEO specialists: Customize robots.txt disallow rules to keep administration and API endpoints out of search results, then rely on the webhook to keep the file current.
How does it work?
You clone the repository into a scripts folder, run yarn install (or npm install), and update the start command to call node sitemap-generator.js after next start. In Strapi admin, you create a webhook with the URL http://localhost:PORT, add an Authorization header with your token, and select create, update, and delete actions. When Strapi sends a webhook request, the generator re-reads content and writes fresh sitemaps; during next build, the webpack hook runs the generate function with your site host, sitemap subfolder, public folder path, and disallowed routes.
FAQ
Is this generator free?
Yes, the source code is publicly available in the stovv/next-strapi-sitemap repository and no commercial license or fee is mentioned.
Does it require Strapi to work?
The webhook-triggered updates require a Strapi instance, because the generator listens for Strapi's webhook calls. The build-time generation can run without Strapi if you call the generate function manually in next.config.js.
Which Node.js setup does it need?
It uses Yarn or npm for dependencies and runs as a Node script alongside Next.js. The instructions assume a typical Next.js project with a scripts folder and a package.json start script.







