Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
Fall back to Yandex and Yep when Bing rate-limits IndexNow submissions (EVE-458) (#1010)
Carter Smithb41c08aee51b
diff --git a/docs/maintainers/specs/0016-indexnow.md b/docs/maintainers/specs/0016-indexnow.mdindex 60eed124..271830bb 100644--- a/docs/maintainers/specs/0016-indexnow.md+++ b/docs/maintainers/specs/0016-indexnow.md@@ -10,7 +10,7 @@ Submissions accept up to 10,000 URLs, the protocol's per-request limit. URLs onBefore submitting for a host, OpenSEO fetches that host's key file. A missing file, a page served in its place, or a redirect stops the submission for that host with instructions to fix the file. Engines expect the file on the exact host, without redirects, so `www.` and the bare domain each need their own copy. Bot protection, server errors and timeouts make the check inconclusive, and the submission goes ahead.-Submissions go to Bing's endpoint, which shares them with the other engines, so its status codes come from the largest participant. Engines answer 202 while a new key is unverified, which is why the key file is checked first. Results are reported per host as submitted or failed, with a message naming the cause or noting that the key is still being verified.+Submissions go to Bing's endpoint first, so status codes come from the largest participant. Any engine shares an accepted submission with the others, so when Bing rate-limits, has a server error or doesn't respond, the same request goes to Yandex and then Yep. Some engines rate-limit requests from shared hosting networks regardless of the site. A rejected key or bad request is reported without trying another engine, since every engine would reject it the same way. Engines answer 202 while a new key is unverified, which is why the key file is checked first. Results are reported per host as submitted or failed, with a message naming the cause or noting that the key is still being verified.Submitting is free. Any member of the organization can set up the key and submit, as with other project research actions.@@ -25,6 +25,8 @@ Automatic submission of pages a site audit found changed would save users a stepLetting users reuse a key they already host, for example from a WordPress plugin, would avoid a second file. Engines accept several keys per host, so the generated key works alongside an existing one.+Sending each submission to every engine would not depend on sharing, but the protocol asks sites to submit to one engine because participants share, and duplicates add load for no gain. Trying engines in order sends one request in the usual case.+A submission history would show what was sent and when. Bing Webmaster Tools already reports what IndexNow received, so v1 shows only the latest result.Hosting the key at a `keyLocation` outside the root would help site builders that cannot serve root files. The protocol limits such a key to URLs in its own directory, so it does not cover a site's pages.diff --git a/src/server/features/indexnow/services/IndexNowService.test.ts b/src/server/features/indexnow/services/IndexNowService.test.tsindex 83a88bb8..81059e76 100644--- a/src/server/features/indexnow/services/IndexNowService.test.ts+++ b/src/server/features/indexnow/services/IndexNowService.test.ts@@ -20,27 +20,35 @@ const KEY = "abc123def456";const scope = { projectId: "p1", organizationId: "o1" };const fetchMock = vi.fn<typeof fetch>();-const isBing = (input: Parameters<typeof fetch>[0]) =>- (input instanceof Request ? input.url : input.toString()).startsWith(- "https://www.bing.com/",- );--// Key files answer with `keyFile`; the Bing endpoint answers with `bing`.-function respond(- keyFile: Response,- bing = new Response(null, { status: 200 }),-) {- fetchMock.mockImplementation(async (input) =>- isBing(input) ? bing.clone() : keyFile.clone(),+const ENGINES = ["www.bing.com", "yandex.com", "indexnow.yep.com"];+const engineOf = (input: Parameters<typeof fetch>[0]) => {+ const { hostname } = new URL(+ input instanceof Request ? input.url : input.toString(),);+ return ENGINES.includes(hostname) ? hostname : null;+};++// Key files answer with `keyFile`; engines answer in ENGINES order with+// `engines`, and with 200 past the end of the list.+function respond(keyFile: Response, ...engines: Response[]) {+ fetchMock.mockImplementation(async (input) => {+ const engine = engineOf(input);+ if (!engine) return keyFile.clone();+ return (+ engines[ENGINES.indexOf(engine)]?.clone() ??+ new Response(null, { status: 200 })+ );+ });}-function bingBodies(): unknown[] {- return fetchMock.mock.calls- .filter(([input]) => isBing(input))- .map(([, init]): unknown =>- typeof init?.body === "string" ? JSON.parse(init.body) : null,- );+function submissions() {+ return fetchMock.mock.calls.flatMap(([input, init]) => {+ const engine = engineOf(input);+ if (!engine) return [];+ const body: unknown =+ typeof init?.body === "string" ? JSON.parse(init.body) : null;+ return [{ engine, body }];+ });}beforeEach(() => {@@ -59,7 +67,7 @@ describe("IndexNowService.submitUrls", () => {"not a url",]);- expect(bingBodies()).toEqual([+ expect(submissions().map((submission) => submission.body)).toEqual([{ host: "example.com", key: KEY, urlList: ["https://example.com/a"] },{host: "www.example.com",@@ -115,7 +123,7 @@ describe("IndexNowService.submitUrls", () => {"https://example.com/a",]);- expect(bingBodies()).toEqual([]);+ expect(submissions()).toEqual([]);expect(result.hosts[0]?.status).toBe("failed");});@@ -129,17 +137,36 @@ describe("IndexNowService.submitUrls", () => {"https://example.com/a",]);- expect(bingBodies()).toHaveLength(1);+ expect(submissions()).toHaveLength(1);+ expect(result.hosts[0]?.status).toBe("submitted");+ });++ it("moves on to the next engine when one rate-limits", async () => {+ respond(+ new Response(KEY),+ new Response(null, { status: 429 }),+ new Response(null, { status: 202 }),+ );++ const result = await IndexNowService.submitUrls(scope, [+ "https://example.com/a",+ ]);++ expect(submissions().map((submission) => submission.engine)).toEqual([+ "www.bing.com",+ "yandex.com",+ ]);expect(result.hosts[0]?.status).toBe("submitted");});- it("reports a key IndexNow rejects", async () => {+ it("reports a key IndexNow rejects without trying other engines", async () => {respond(new Response(KEY), new Response(null, { status: 403 }));const result = await IndexNowService.submitUrls(scope, ["https://example.com/a",]);+ expect(submissions()).toHaveLength(1);expect(result.hosts[0]?.status).toBe("failed");expect(result.hosts[0]?.message).toContain("https://example.com");});diff --git a/src/server/features/indexnow/services/IndexNowService.ts b/src/server/features/indexnow/services/IndexNowService.tsindex 1f95ac79..6b4fb21a 100644--- a/src/server/features/indexnow/services/IndexNowService.ts+++ b/src/server/features/indexnow/services/IndexNowService.ts@@ -3,10 +3,15 @@ import { normalizeAndValidateStartUrl } from "@/server/lib/audit/url-policy";import { AppError } from "@/server/lib/errors";import { readBoundedText } from "@/server/lib/scrape";-// Bing shares every submission with the other IndexNow engines (Yandex,-// Seznam, Naver, Yep, ...), so one request reaches all of them, and its status-// codes come from the largest participant.-const INDEXNOW_ENDPOINT = "https://www.bing.com/indexnow";+// IndexNow engines share every submission with each other, so one accepted+// request reaches all of them. Bing goes first as the largest participant. Bing+// and some other engines rate-limit shared hosting IPs, including Cloudflare+// Workers', so a rate limit, server error or timeout moves on to the next one.+const INDEXNOW_ENDPOINTS = [+ "https://www.bing.com/indexnow",+ "https://yandex.com/indexnow",+ "https://indexnow.yep.com/indexnow",+];const REQUEST_TIMEOUT_MS = 10_000;interface ProjectScope {@@ -118,7 +123,7 @@ function describeResponse(return {status: "failed",message:- "Too many submissions for this site. Wait before trying again, and only submit pages that changed.",+ "Search engines are refusing submissions right now. Try again later, and only submit pages that changed.",};default:return {@@ -128,6 +133,38 @@ function describeResponse(}}+/** The engine's status code, or undefined when it didn't respond. */+async function postToEngine(+ endpoint: string,+ host: string,+ body: string,+): Promise<number | undefined> {+ let response: Response;+ try {+ response = await fetch(endpoint, {+ method: "POST",+ headers: { "content-type": "application/json; charset=utf-8" },+ body,+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),+ });+ } catch (error) {+ console.warn(+ `indexnow.submit ${endpoint} network error for ${host}`,+ error,+ );+ return undefined;+ }+ if (response.ok) {+ void response.body?.cancel().catch(() => {});+ } else {+ const detail = await readBoundedText(response).catch(() => null);+ console.warn(+ `indexnow.submit ${endpoint} HTTP ${response.status} for ${host}: ${detail?.slice(0, 200) ?? ""}`,+ );+ }+ return response.status;+}+async function submitHost(host: string,key: string,@@ -137,29 +174,20 @@ async function submitHost(const problem = await findKeyFileProblem(host, key);if (problem) return { ...base, status: "failed", message: problem };- let response: Response;- try {- response = await fetch(INDEXNOW_ENDPOINT, {- method: "POST",- headers: { "content-type": "application/json; charset=utf-8" },- body: JSON.stringify({ host, key, urlList }),- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),- });- } catch (error) {- console.warn("indexnow.submit network error", error);+ const body = JSON.stringify({ host, key, urlList });+ let status: number | undefined;+ for (const endpoint of INDEXNOW_ENDPOINTS) {+ status = await postToEngine(endpoint, host, body);+ if (status !== undefined && status !== 429 && status < 500) break;+ }+ if (status === undefined) {return {...base,status: "failed",message: "IndexNow didn't respond. Try again later.",};}- if (response.status >= 300) {- console.warn(`indexnow.submit HTTP ${response.status} for ${host}`);- }- return {- ...base,- ...describeResponse(response.status, urlList.length, host),- };+ return { ...base, ...describeResponse(status, urlList.length, host) };}/**