Fix GitHub widget/data endpoints to prefer /github/api routes

This commit is contained in:
svemagie
2026-03-08 05:44:36 +01:00
parent 64e861873e
commit 722ff22328
10 changed files with 120 additions and 60 deletions
+11 -4
View File
@@ -16,23 +16,30 @@ const FALLBACK_FEATURED_REPOS = process.env.GITHUB_FEATURED_REPOS?.split(",").fi
* Fetch from Indiekit's public GitHub API endpoint * Fetch from Indiekit's public GitHub API endpoint
*/ */
async function fetchFromIndiekit(endpoint) { async function fetchFromIndiekit(endpoint) {
const urls = [
`${INDIEKIT_URL}/github/api/${endpoint}`,
`${INDIEKIT_URL}/githubapi/api/${endpoint}`,
];
for (const url of urls) {
try { try {
const url = `${INDIEKIT_URL}/githubapi/api/${endpoint}`;
console.log(`[githubActivity] Fetching from Indiekit: ${url}`); console.log(`[githubActivity] Fetching from Indiekit: ${url}`);
const data = await EleventyFetch(url, { const data = await EleventyFetch(url, {
duration: "15m", duration: "15m",
type: "json", type: "json",
}); });
console.log(`[githubActivity] Indiekit ${endpoint} success`); console.log(`[githubActivity] Indiekit ${endpoint} success via ${url}`);
return data; return data;
} catch (error) { } catch (error) {
console.log( console.log(
`[githubActivity] Indiekit API unavailable for ${endpoint}: ${error.message}` `[githubActivity] Indiekit API unavailable for ${endpoint} at ${url}: ${error.message}`
); );
return null;
} }
} }
return null;
}
/** /**
* Fetch from GitHub API directly * Fetch from GitHub API directly
*/ */
+13 -1
View File
@@ -12,7 +12,13 @@ const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
export default async function () { export default async function () {
try { try {
const url = `${INDIEKIT_URL}/githubapi/api/starred/all`; const urls = [
`${INDIEKIT_URL}/github/api/starred/all`,
`${INDIEKIT_URL}/githubapi/api/starred/all`,
];
for (const url of urls) {
try {
const response = await EleventyFetch(url, { const response = await EleventyFetch(url, {
duration: "15m", duration: "15m",
type: "json", type: "json",
@@ -22,6 +28,12 @@ export default async function () {
totalCount: response.totalCount || 0, totalCount: response.totalCount || 0,
buildDate: new Date().toISOString(), buildDate: new Date().toISOString(),
}; };
} catch (error) {
console.log(`[githubStarred] Could not fetch ${url}: ${error.message}`);
}
}
throw new Error("No GitHub starred endpoint responded");
} catch (error) { } catch (error) {
console.log(`[githubStarred] Could not fetch starred count: ${error.message}`); console.log(`[githubStarred] Could not fetch starred count: ${error.message}`);
return { return {
@@ -255,9 +255,9 @@ function githubWidget(username) {
try { try {
const [commitsRes, featuredRes, contribRes] = await Promise.all([ const [commitsRes, featuredRes, contribRes] = await Promise.all([
this.fetchJson(['/githubapi/api/commits', '/github/api/commits']), this.fetchJson(['/github/api/commits', '/githubapi/api/commits']),
this.fetchJson(['/githubapi/api/featured', '/github/api/featured']), this.fetchJson(['/github/api/featured', '/githubapi/api/featured']),
this.fetchJson(['/githubapi/api/contributions', '/github/api/contributions']), this.fetchJson(['/github/api/contributions', '/githubapi/api/contributions']),
]); ]);
if (commitsRes.ok) { if (commitsRes.ok) {
+1 -1
View File
@@ -182,8 +182,8 @@ function changelogApp() {
async fetchChangelog(days) { async fetchChangelog(days) {
try { try {
const result = await this.fetchJson([ const result = await this.fetchJson([
'/githubapi/api/changelog?days=' + days,
'/github/api/changelog?days=' + days, '/github/api/changelog?days=' + days,
'/githubapi/api/changelog?days=' + days,
]); ]);
if (!result.ok) throw new Error('Failed to fetch'); if (!result.ok) throw new Error('Failed to fetch');
+14 -3
View File
@@ -422,9 +422,20 @@ document.addEventListener("alpine:init", () => {
async init() { async init() {
try { try {
const res = await fetch("/githubapi/api/starred/all"); let data = null;
if (!res.ok) throw new Error("API returned " + res.status); for (const path of ["/github/api/starred/all", "/githubapi/api/starred/all"]) {
const data = await res.json(); try {
const res = await fetch(path);
if (res.ok) {
data = await res.json();
break;
}
} catch {
// Try next candidate path.
}
}
if (!data) throw new Error("API returned no usable response");
this.allStars = data.stars || []; this.allStars = data.stars || [];
this.listMeta = (data.listMeta || []).sort((a, b) => a.name.localeCompare(b.name)); this.listMeta = (data.listMeta || []).sort((a, b) => a.name.localeCompare(b.name));
this.totalCount = data.totalCount || 0; this.totalCount = data.totalCount || 0;
+11 -4
View File
@@ -16,23 +16,30 @@ const FALLBACK_FEATURED_REPOS = process.env.GITHUB_FEATURED_REPOS?.split(",").fi
* Fetch from Indiekit's public GitHub API endpoint * Fetch from Indiekit's public GitHub API endpoint
*/ */
async function fetchFromIndiekit(endpoint) { async function fetchFromIndiekit(endpoint) {
const urls = [
`${INDIEKIT_URL}/github/api/${endpoint}`,
`${INDIEKIT_URL}/githubapi/api/${endpoint}`,
];
for (const url of urls) {
try { try {
const url = `${INDIEKIT_URL}/githubapi/api/${endpoint}`;
console.log(`[githubActivity] Fetching from Indiekit: ${url}`); console.log(`[githubActivity] Fetching from Indiekit: ${url}`);
const data = await EleventyFetch(url, { const data = await EleventyFetch(url, {
duration: "15m", duration: "15m",
type: "json", type: "json",
}); });
console.log(`[githubActivity] Indiekit ${endpoint} success`); console.log(`[githubActivity] Indiekit ${endpoint} success via ${url}`);
return data; return data;
} catch (error) { } catch (error) {
console.log( console.log(
`[githubActivity] Indiekit API unavailable for ${endpoint}: ${error.message}` `[githubActivity] Indiekit API unavailable for ${endpoint} at ${url}: ${error.message}`
); );
return null;
} }
} }
return null;
}
/** /**
* Fetch from GitHub API directly * Fetch from GitHub API directly
*/ */
+13 -1
View File
@@ -12,7 +12,13 @@ const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
export default async function () { export default async function () {
try { try {
const url = `${INDIEKIT_URL}/githubapi/api/starred/all`; const urls = [
`${INDIEKIT_URL}/github/api/starred/all`,
`${INDIEKIT_URL}/githubapi/api/starred/all`,
];
for (const url of urls) {
try {
const response = await EleventyFetch(url, { const response = await EleventyFetch(url, {
duration: "15m", duration: "15m",
type: "json", type: "json",
@@ -22,6 +28,12 @@ export default async function () {
totalCount: response.totalCount || 0, totalCount: response.totalCount || 0,
buildDate: new Date().toISOString(), buildDate: new Date().toISOString(),
}; };
} catch (error) {
console.log(`[githubStarred] Could not fetch ${url}: ${error.message}`);
}
}
throw new Error("No GitHub starred endpoint responded");
} catch (error) { } catch (error) {
console.log(`[githubStarred] Could not fetch starred count: ${error.message}`); console.log(`[githubStarred] Could not fetch starred count: ${error.message}`);
return { return {
@@ -247,9 +247,9 @@ function githubWidget(username) {
try { try {
const [commitsRes, featuredRes, contribRes] = await Promise.all([ const [commitsRes, featuredRes, contribRes] = await Promise.all([
this.fetchJson(['/githubapi/api/commits', '/github/api/commits']), this.fetchJson(['/github/api/commits', '/githubapi/api/commits']),
this.fetchJson(['/githubapi/api/featured', '/github/api/featured']), this.fetchJson(['/github/api/featured', '/githubapi/api/featured']),
this.fetchJson(['/githubapi/api/contributions', '/github/api/contributions']), this.fetchJson(['/github/api/contributions', '/githubapi/api/contributions']),
]); ]);
if (commitsRes.ok) { if (commitsRes.ok) {
+1 -1
View File
@@ -180,8 +180,8 @@ function changelogApp() {
async fetchChangelog(days) { async fetchChangelog(days) {
try { try {
const result = await this.fetchJson([ const result = await this.fetchJson([
'/githubapi/api/changelog?days=' + days,
'/github/api/changelog?days=' + days, '/github/api/changelog?days=' + days,
'/githubapi/api/changelog?days=' + days,
]); ]);
if (!result.ok) throw new Error('Failed to fetch'); if (!result.ok) throw new Error('Failed to fetch');
+14 -3
View File
@@ -416,9 +416,20 @@ document.addEventListener("alpine:init", () => {
async init() { async init() {
try { try {
const res = await fetch("/githubapi/api/starred/all"); let data = null;
if (!res.ok) throw new Error("API returned " + res.status); for (const path of ["/github/api/starred/all", "/githubapi/api/starred/all"]) {
const data = await res.json(); try {
const res = await fetch(path);
if (res.ok) {
data = await res.json();
break;
}
} catch {
// Try next candidate path.
}
}
if (!data) throw new Error("API returned no usable response");
this.allStars = data.stars || []; this.allStars = data.stars || [];
this.listMeta = (data.listMeta || []).sort((a, b) => a.name.localeCompare(b.name)); this.listMeta = (data.listMeta || []).sort((a, b) => a.name.localeCompare(b.name));
this.totalCount = data.totalCount || 0; this.totalCount = data.totalCount || 0;