Return empty list if no instances could be fetched
This commit is contained in:
parent
2871f3f6e8
commit
808ab27ed4
1 changed files with 17 additions and 8 deletions
|
@ -6,16 +6,25 @@
|
||||||
import { APIRoute } from "astro";
|
import { APIRoute } from "astro";
|
||||||
|
|
||||||
export const get: APIRoute = async () => {
|
export const get: APIRoute = async () => {
|
||||||
const response = await fetch("https://api.joinmastodon.org/servers");
|
try {
|
||||||
const instances = await response.json();
|
const response = await fetch("https://api.joinmastodon.org/servers");
|
||||||
|
const instances = await response.json();
|
||||||
|
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify(instances.map((instance) => instance.domain)),
|
JSON.stringify(instances.map((instance) => instance.domain)),
|
||||||
{
|
{
|
||||||
|
headers: {
|
||||||
|
"Cache-Control": "s-maxage=86400, max-age=86400, public",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Could not fetch instances:", error);
|
||||||
|
return new Response(JSON.stringify([]), {
|
||||||
headers: {
|
headers: {
|
||||||
"Cache-Control": "s-maxage=86400, max-age=86400, public",
|
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
);
|
}
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue