nuxt-ai-ready 0.7.15 → 0.7.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -7,14 +7,14 @@ export interface IndexNowResult {
|
|
|
7
7
|
backoff?: boolean;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* Submit URLs to IndexNow API
|
|
10
|
+
* Submit URLs to IndexNow API with fallback on rate limit
|
|
11
11
|
*/
|
|
12
12
|
export declare function submitToIndexNow(routes: string[], config: {
|
|
13
13
|
key: string;
|
|
14
|
-
host?: string;
|
|
15
14
|
}, siteUrl: string): Promise<{
|
|
16
15
|
success: boolean;
|
|
17
16
|
error?: string;
|
|
17
|
+
host?: string;
|
|
18
18
|
}>;
|
|
19
19
|
/**
|
|
20
20
|
* Submit pending pages to IndexNow
|
|
@@ -30,12 +30,11 @@ async function setBackoffInfo(event, info) {
|
|
|
30
30
|
await db.exec("DELETE FROM _ai_ready_info WHERE id = ?", ["indexnow_backoff"]);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
const INDEXNOW_HOSTS = ["api.indexnow.org", "www.bing.com"];
|
|
33
34
|
export async function submitToIndexNow(routes, config, siteUrl) {
|
|
34
35
|
if (!siteUrl) {
|
|
35
36
|
return { success: false, error: "Site URL not configured" };
|
|
36
37
|
}
|
|
37
|
-
const host = config.host || "api.indexnow.org";
|
|
38
|
-
const endpoint = `https://${host}/indexnow`;
|
|
39
38
|
const urlList = routes.map(
|
|
40
39
|
(route) => route.startsWith("http") ? route : `${siteUrl}${route}`
|
|
41
40
|
);
|
|
@@ -45,18 +44,28 @@ export async function submitToIndexNow(routes, config, siteUrl) {
|
|
|
45
44
|
keyLocation: `${siteUrl}/${config.key}.txt`,
|
|
46
45
|
urlList
|
|
47
46
|
};
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
let lastError;
|
|
48
|
+
for (const host of INDEXNOW_HOSTS) {
|
|
49
|
+
const endpoint = `https://${host}/indexnow`;
|
|
50
|
+
logger.debug(`[indexnow] Submitting ${urlList.length} URLs to ${endpoint}`);
|
|
51
|
+
const response = await $fetch(endpoint, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: { "Content-Type": "application/json" },
|
|
54
|
+
body
|
|
55
|
+
}).catch((err) => ({ error: err.message }));
|
|
56
|
+
if (response && typeof response === "object" && "error" in response) {
|
|
57
|
+
lastError = response.error;
|
|
58
|
+
if (lastError.includes("429")) {
|
|
59
|
+
logger.warn(`[indexnow] Rate limited on ${host}, trying fallback...`);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
logger.warn(`[indexnow] Submission failed on ${host}: ${lastError}`);
|
|
63
|
+
return { success: false, error: lastError, host };
|
|
64
|
+
}
|
|
65
|
+
logger.debug(`[indexnow] Successfully submitted ${urlList.length} URLs via ${host}`);
|
|
66
|
+
return { success: true, host };
|
|
57
67
|
}
|
|
58
|
-
|
|
59
|
-
return { success: true };
|
|
68
|
+
return { success: false, error: lastError || "All endpoints rate limited", host: INDEXNOW_HOSTS[INDEXNOW_HOSTS.length - 1] };
|
|
60
69
|
}
|
|
61
70
|
export async function syncToIndexNow(event, limit = 100) {
|
|
62
71
|
const config = useRuntimeConfig(event)["nuxt-ai-ready"];
|