cmux/web/app/api/github-stars/route.ts
Lawrence Chen 2e2e190bf4
Add GitHub star count to site header (#673)
* Add GitHub star count to site header

Fetches star count from GitHub API via /api/github-stars with 5-minute
server-side caching (ISR + stale-while-revalidate). Shows formatted
count (e.g. "2.2k") next to the GitHub link in both desktop nav and
mobile drawer.

* Move star count to separate badge left of download button

GitHub icon + formatted count as its own clickable element in the
right header section, separate from the nav links. Desktop only.

* Center GitHub stars badge vertically in header

* Add right padding to GitHub stars badge
2026-02-28 17:02:19 -08:00

33 lines
794 B
TypeScript

import { NextResponse } from "next/server";
export const revalidate = 300; // ISR: regenerate every 5 minutes
export async function GET() {
try {
const res = await fetch(
"https://api.github.com/repos/manaflow-ai/cmux",
{
headers: { Accept: "application/vnd.github.v3+json" },
next: { revalidate: 300 },
}
);
if (!res.ok) {
return NextResponse.json({ stars: null }, { status: 502 });
}
const data = await res.json();
const stars: number = data.stargazers_count;
return NextResponse.json(
{ stars },
{
headers: {
"Cache-Control": "public, s-maxage=300, stale-while-revalidate=600",
},
}
);
} catch {
return NextResponse.json({ stars: null }, { status: 502 });
}
}