Harden listening data endpoints with route fallbacks
This commit is contained in:
@@ -5,28 +5,36 @@
|
|||||||
|
|
||||||
import EleventyFetch from "@11ty/eleventy-fetch";
|
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||||
|
|
||||||
const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
|
const INDIEKIT_URL =
|
||||||
|
process.env.INDIEKIT_URL || process.env.SITE_URL || "https://example.com";
|
||||||
const FUNKWHALE_INSTANCE = process.env.FUNKWHALE_INSTANCE || "";
|
const FUNKWHALE_INSTANCE = process.env.FUNKWHALE_INSTANCE || "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch from Indiekit's public Funkwhale API endpoint
|
* Fetch from Indiekit's public Funkwhale API endpoint
|
||||||
*/
|
*/
|
||||||
async function fetchFromIndiekit(endpoint) {
|
async function fetchFromIndiekit(endpoint) {
|
||||||
|
const urls = [
|
||||||
|
`${INDIEKIT_URL}/funkwhale/api/${endpoint}`,
|
||||||
|
`${INDIEKIT_URL}/funkwhaleapi/api/${endpoint}`,
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const url of urls) {
|
||||||
try {
|
try {
|
||||||
const url = `${INDIEKIT_URL}/funkwhaleapi/api/${endpoint}`;
|
|
||||||
console.log(`[funkwhaleActivity] Fetching from Indiekit: ${url}`);
|
console.log(`[funkwhaleActivity] Fetching from Indiekit: ${url}`);
|
||||||
const data = await EleventyFetch(url, {
|
const data = await EleventyFetch(url, {
|
||||||
duration: "15m",
|
duration: "15m",
|
||||||
type: "json",
|
type: "json",
|
||||||
});
|
});
|
||||||
console.log(`[funkwhaleActivity] Indiekit ${endpoint} success`);
|
console.log(`[funkwhaleActivity] Indiekit ${endpoint} success via ${url}`);
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(
|
console.log(
|
||||||
`[funkwhaleActivity] Indiekit API unavailable for ${endpoint}: ${error.message}`
|
`[funkwhaleActivity] Indiekit API unavailable for ${endpoint} at ${url}: ${error.message}`
|
||||||
);
|
);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+13
-5
@@ -5,28 +5,36 @@
|
|||||||
|
|
||||||
import EleventyFetch from "@11ty/eleventy-fetch";
|
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||||
|
|
||||||
const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
|
const INDIEKIT_URL =
|
||||||
|
process.env.INDIEKIT_URL || process.env.SITE_URL || "https://example.com";
|
||||||
const LASTFM_USERNAME = process.env.LASTFM_USERNAME || "";
|
const LASTFM_USERNAME = process.env.LASTFM_USERNAME || "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch from Indiekit's public Last.fm API endpoint
|
* Fetch from Indiekit's public Last.fm API endpoint
|
||||||
*/
|
*/
|
||||||
async function fetchFromIndiekit(endpoint) {
|
async function fetchFromIndiekit(endpoint) {
|
||||||
|
const urls = [
|
||||||
|
`${INDIEKIT_URL}/lastfmapi/api/${endpoint}`,
|
||||||
|
`${INDIEKIT_URL}/lastfm/api/${endpoint}`,
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const url of urls) {
|
||||||
try {
|
try {
|
||||||
const url = `${INDIEKIT_URL}/lastfmapi/api/${endpoint}`;
|
|
||||||
console.log(`[lastfmActivity] Fetching from Indiekit: ${url}`);
|
console.log(`[lastfmActivity] Fetching from Indiekit: ${url}`);
|
||||||
const data = await EleventyFetch(url, {
|
const data = await EleventyFetch(url, {
|
||||||
duration: "15m",
|
duration: "15m",
|
||||||
type: "json",
|
type: "json",
|
||||||
});
|
});
|
||||||
console.log(`[lastfmActivity] Indiekit ${endpoint} success`);
|
console.log(`[lastfmActivity] Indiekit ${endpoint} success via ${url}`);
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(
|
console.log(
|
||||||
`[lastfmActivity] Indiekit API unavailable for ${endpoint}: ${error.message}`
|
`[lastfmActivity] Indiekit API unavailable for ${endpoint} at ${url}: ${error.message}`
|
||||||
);
|
);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function () {
|
export default async function () {
|
||||||
|
|||||||
@@ -5,28 +5,36 @@
|
|||||||
|
|
||||||
import EleventyFetch from "@11ty/eleventy-fetch";
|
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||||
|
|
||||||
const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
|
const INDIEKIT_URL =
|
||||||
|
process.env.INDIEKIT_URL || process.env.SITE_URL || "https://example.com";
|
||||||
const FUNKWHALE_INSTANCE = process.env.FUNKWHALE_INSTANCE || "";
|
const FUNKWHALE_INSTANCE = process.env.FUNKWHALE_INSTANCE || "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch from Indiekit's public Funkwhale API endpoint
|
* Fetch from Indiekit's public Funkwhale API endpoint
|
||||||
*/
|
*/
|
||||||
async function fetchFromIndiekit(endpoint) {
|
async function fetchFromIndiekit(endpoint) {
|
||||||
|
const urls = [
|
||||||
|
`${INDIEKIT_URL}/funkwhale/api/${endpoint}`,
|
||||||
|
`${INDIEKIT_URL}/funkwhaleapi/api/${endpoint}`,
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const url of urls) {
|
||||||
try {
|
try {
|
||||||
const url = `${INDIEKIT_URL}/funkwhaleapi/api/${endpoint}`;
|
|
||||||
console.log(`[funkwhaleActivity] Fetching from Indiekit: ${url}`);
|
console.log(`[funkwhaleActivity] Fetching from Indiekit: ${url}`);
|
||||||
const data = await EleventyFetch(url, {
|
const data = await EleventyFetch(url, {
|
||||||
duration: "15m",
|
duration: "15m",
|
||||||
type: "json",
|
type: "json",
|
||||||
});
|
});
|
||||||
console.log(`[funkwhaleActivity] Indiekit ${endpoint} success`);
|
console.log(`[funkwhaleActivity] Indiekit ${endpoint} success via ${url}`);
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(
|
console.log(
|
||||||
`[funkwhaleActivity] Indiekit API unavailable for ${endpoint}: ${error.message}`
|
`[funkwhaleActivity] Indiekit API unavailable for ${endpoint} at ${url}: ${error.message}`
|
||||||
);
|
);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,28 +5,36 @@
|
|||||||
|
|
||||||
import EleventyFetch from "@11ty/eleventy-fetch";
|
import EleventyFetch from "@11ty/eleventy-fetch";
|
||||||
|
|
||||||
const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
|
const INDIEKIT_URL =
|
||||||
|
process.env.INDIEKIT_URL || process.env.SITE_URL || "https://example.com";
|
||||||
const LASTFM_USERNAME = process.env.LASTFM_USERNAME || "";
|
const LASTFM_USERNAME = process.env.LASTFM_USERNAME || "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch from Indiekit's public Last.fm API endpoint
|
* Fetch from Indiekit's public Last.fm API endpoint
|
||||||
*/
|
*/
|
||||||
async function fetchFromIndiekit(endpoint) {
|
async function fetchFromIndiekit(endpoint) {
|
||||||
|
const urls = [
|
||||||
|
`${INDIEKIT_URL}/lastfmapi/api/${endpoint}`,
|
||||||
|
`${INDIEKIT_URL}/lastfm/api/${endpoint}`,
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const url of urls) {
|
||||||
try {
|
try {
|
||||||
const url = `${INDIEKIT_URL}/lastfmapi/api/${endpoint}`;
|
|
||||||
console.log(`[lastfmActivity] Fetching from Indiekit: ${url}`);
|
console.log(`[lastfmActivity] Fetching from Indiekit: ${url}`);
|
||||||
const data = await EleventyFetch(url, {
|
const data = await EleventyFetch(url, {
|
||||||
duration: "15m",
|
duration: "15m",
|
||||||
type: "json",
|
type: "json",
|
||||||
});
|
});
|
||||||
console.log(`[lastfmActivity] Indiekit ${endpoint} success`);
|
console.log(`[lastfmActivity] Indiekit ${endpoint} success via ${url}`);
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(
|
console.log(
|
||||||
`[lastfmActivity] Indiekit API unavailable for ${endpoint}: ${error.message}`
|
`[lastfmActivity] Indiekit API unavailable for ${endpoint} at ${url}: ${error.message}`
|
||||||
);
|
);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function () {
|
export default async function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user