Skip to content

Commit d4f6025

Browse files
authored
feat: enable leaderboard calculation endpoint with configuration toggle (#180)
1 parent 3c7a2ab commit d4f6025

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ GITHUB_DISCUSSION_COUNT=10
1212

1313
# Leaderboard source data
1414
LEADERBOARD_SOURCE_URL_TEMPLATE=https://raw.githubusercontent.com/ashkulz/committers.top/gh-pages/_data/locations/{country}.yml
15+
DISABLE_CALCULATE_LEADERBOARD_ENDPOINT=false
1516

1617
# Redis caching (optional — strongly recommended for leaderboard performance)
1718
# Use either redis://localhost:6379 or include password if enabled: redis://:password@localhost:6379
@@ -24,4 +25,4 @@ REDIS_CONNECT_TIMEOUT_MS=1500
2425

2526
# ── PostgreSQL (local development) ─────────────────
2627
DATABASE_URL=postgresql://devimpact:devimpact@localhost:5432/devimpact?sslmode=disable
27-
POSTGRES_PASSWORD=CHANGE_THIS_TO_A_LONG_RANDOM_PASSWORD
28+
POSTGRES_PASSWORD=CHANGE_THIS_TO_A_LONG_RANDOM_PASSWORD

app/api/calculate-leaderboard/route.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@ import { calculateLeaderboard } from "@/lib/calculate-leaderboard";
33

44
export const runtime = "nodejs";
55

6+
function isCalculateLeaderboardDisabled(): boolean {
7+
const raw =
8+
process.env.DISABLE_CALCULATE_LEADERBOARD_ENDPOINT?.trim().toLowerCase();
9+
return raw === "true" || raw === "1" || raw === "yes";
10+
}
11+
612
export async function POST(request: Request) {
13+
if (isCalculateLeaderboardDisabled()) {
14+
return NextResponse.json(
15+
{ success: false, error: "Not found" },
16+
{ status: 404 },
17+
);
18+
}
19+
720
const { searchParams } = new URL(request.url);
821
const country = searchParams.get("country")?.trim();
922

@@ -26,4 +39,4 @@ export async function POST(request: Request) {
2639
{ status: 502 },
2740
);
2841
}
29-
}
42+
}

0 commit comments

Comments
 (0)