Skip to content

Commit de93112

Browse files
committed
1.8.0 – IndexNow integration
1 parent 141d234 commit de93112

3 files changed

Lines changed: 80 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "githubster",
3-
"version": "1.7.0",
3+
"version": "1.8.0",
44
"description": "Track your GitHub followers, unfollowers, and following relationships",
55
"license": "MIT",
66
"scripts": {

src/app/[key]/route.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
3+
export async function GET(
4+
_request: NextRequest,
5+
{ params }: { params: Promise<{ key: string }> }
6+
) {
7+
const { key } = await params;
8+
const indexNowKey = process.env.INDEXNOW_KEY;
9+
10+
// Only respond if the requested file matches {INDEXNOW_KEY}.txt pattern
11+
if (!indexNowKey || key !== `${indexNowKey}.txt`) {
12+
return NextResponse.json({ error: "Not found" }, { status: 404 });
13+
}
14+
15+
return new Response(indexNowKey, {
16+
headers: {
17+
"Content-Type": "text/plain; charset=utf-8",
18+
},
19+
});
20+
}

src/app/api/indexnow/route.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { NextResponse } from "next/server";
2+
3+
const INDEXNOW_KEY = process.env.INDEXNOW_KEY;
4+
const SITE_URL = "https://www.githubster.com";
5+
6+
const URLS_TO_INDEX = [
7+
SITE_URL,
8+
];
9+
10+
export async function GET() {
11+
if (!INDEXNOW_KEY) {
12+
return NextResponse.json(
13+
{ success: false, message: "INDEXNOW_KEY is not configured" },
14+
{ status: 500 }
15+
);
16+
}
17+
18+
try {
19+
const response = await fetch("https://api.indexnow.org/indexnow", {
20+
method: "POST",
21+
headers: {
22+
"Content-Type": "application/json; charset=utf-8",
23+
},
24+
body: JSON.stringify({
25+
host: "www.githubster.com",
26+
key: INDEXNOW_KEY,
27+
keyLocation: `${SITE_URL}/${INDEXNOW_KEY}.txt`,
28+
urlList: URLS_TO_INDEX,
29+
}),
30+
});
31+
32+
if (response.ok || response.status === 202) {
33+
return NextResponse.json({
34+
success: true,
35+
status: response.status,
36+
message: "URLs submitted to IndexNow successfully",
37+
urls: URLS_TO_INDEX,
38+
});
39+
}
40+
41+
const text = await response.text();
42+
return NextResponse.json(
43+
{
44+
success: false,
45+
status: response.status,
46+
message: `IndexNow API error: ${text}`,
47+
},
48+
{ status: response.status }
49+
);
50+
} catch (error) {
51+
return NextResponse.json(
52+
{
53+
success: false,
54+
message: error instanceof Error ? error.message : "Unknown error",
55+
},
56+
{ status: 500 }
57+
);
58+
}
59+
}

0 commit comments

Comments
 (0)