If you host your own Next.js site (Coolify, Dokku, a plain VPS with Docker) you lose one thing Vercel gives you for free: a clear "this commit is now live" event. That matters the moment you want to do something after a deploy, like telling search engines your pages changed.
IndexNow is the protocol Bing, Yandex, Seznam and Naver share: one POST with a list of URLs, and all of them hear about it. If you send it too early, while the old container is still serving, the crawler can arrive, fetch the old page and decide nothing changed.
Here's the small setup I use on a German photo site, FotoKlar: a health endpoint that reports the deployed commit, and a GitHub Action that waits for that commit before it pings IndexNow.
1. A health endpoint that knows its commit
Coolify can pass the Git commit into the build as SOURCE_COMMIT (the "Include Source Commit in Build" option). The route just echoes it:
// src/app/api/health/route.ts import { NextResponse } from "next/server"; export function GET() { return NextResponse.json( { ok: true, commit: process.env.SOURCE_COMMIT || null }, { headers: { "Cache-Control": "no-store" } }, ); } The same endpoint doubles as the Docker HEALTHCHECK and Coolify's health check, so it's cheap and has no upstream calls or secrets. no-store matters: a CDN that caches it would tell you the wrong commit.
2. Wait for this commit, not just "the site is up"
The workflow runs on every push to main, then polls the health endpoint until it reports the pushed SHA:
name: IndexNow on: push: branches: [main] workflow_dispatch: concurrency: group: indexnow cancel-in-progress: true jobs: submit: runs-on: ubuntu-latest timeout-minutes: 20 steps: - name: Wait for the deploy of this commit id: wait if: github.event_name == 'push' run: | for i in $(seq 1 30); do live=$(curl -fsS https://example.com/api/health/ \ | sed -n 's/.*"commit":"\([0-9a-f]*\)".*/\1/p' || true) if [ "$live" = "${{ github.sha }}" ]; then echo "Deployed: $live"; exit 0; fi echo "Live commit: ${live:-none}; waiting..."; sleep 30 done echo "::notice::Commit not live after 15 minutes; IndexNow skipped" echo "skip=true" >> "$GITHUB_OUTPUT" - uses: actions/checkout@v4 if: steps.wait.outputs.skip != 'true' - uses: actions/setup-node@v4 if: steps.wait.outputs.skip != 'true' with: node-version: 22 - name: Submit sitemap URLs if: steps.wait.outputs.skip != 'true' run: node scripts/indexnow.mjs --all A few details that took a couple of iterations:
- Compare the exact SHA. "Health returns 200" is true for the old container during a rolling update too.
- Skip, don't fail. If the deploy itself failed, a red IndexNow job is just noise. A
::notice::and a skipped step is enough. -
concurrencywithcancel-in-progress. Two quick pushes would otherwise produce two jobs waiting for two commits, and the first one can never succeed. -
workflow_dispatchlets you resubmit by hand without the wait step (it's guarded byif: github.event_name == 'push').
3. The submit script: read the live sitemap
Rather than hard-coding URLs, the script reads the deployed sitemap, so it always matches what's actually live:
const keyFile = readdirSync(new URL("../public/", import.meta.url)) .find(f => /^[a-f0-9]{32}\.txt$/.test(f)); const key = readFileSync(new URL(`../public/${keyFile}`, import.meta.url), "utf8").trim(); const keyLocation = `${base}/${keyFile}`; // The engines fetch the key from the site; refuse to submit if it isn't served yet. const served = await fetch(keyLocation).then(r => (r.ok ? r.text() : "")).catch(() => ""); if (served.trim() !== key) throw new Error(`Key file not served at ${keyLocation} yet`); const sitemap = await (await fetch(`${base}/sitemap.xml`)).text(); const entries = [...sitemap.matchAll(/<url>([\s\S]*?)<\/url>/g)].map(([, block]) => ({ loc: (block.match(/<loc>([^<]+)<\/loc>/) || [])[1], lastmod: (block.match(/<lastmod>([^<]+)<\/lastmod>/) || [])[1], })); // By default only pages changed in the last N days; --all sends everything. const since = Date.now() - days * 86_400_000; const urlList = entries .filter(e => e.loc && (args.all || (e.lastmod && Date.parse(e.lastmod) >= since))) .map(e => e.loc); const res = await fetch("https://api.indexnow.org/indexnow", { method: "POST", headers: { "Content-Type": "application/json; charset=utf-8" }, body: JSON.stringify({ host, key, keyLocation, urlList }), }); // 200 OK and 202 Accepted are both success (202: key validation pending). if (res.status !== 200 && res.status !== 202) process.exit(1); Things worth knowing about IndexNow itself:
- The key is public by design. It's a text file at your site root containing the key; that's how engines verify you own the host. Don't treat it as a secret.
- One call reaches all participating engines. You don't need separate Bing and Yandex submissions.
- 202 is success, it just means the key hasn't been verified yet.
- Up to 10,000 URLs per call, so for a small site sending the whole sitemap on each deploy is fine. The site this comes from has about 80 URLs in German and English.
- It doesn't cover Google. Google doesn't take IndexNow; resubmitting the sitemap in Search Console is still a separate step.
4. --dry-run before you trust it
node scripts/indexnow.mjs --dry-run prints exactly which URLs would go out. Worth running once against production: it's the quickest way to catch a sitemap with the wrong host, missing trailing slashes, or lastmod dates that never change.
Takeaways
- Expose the deployed commit on a no-cache health endpoint.
- In CI, wait for that exact SHA, then act; skip quietly if it never shows up.
- Build the URL list from the live sitemap, not from the repo.
- Verify the key file is served before you submit.
The site this is running on is FotoKlar, a German/English tool for biometric and job application photos. Disclosure: it's my own project.
This post was drafted with help from an AI assistant and checked against the production code.
