fix: don't error out if API is not running during frontend build
This commit is contained in:
parent
b7e0286cc7
commit
8f8daaa331
1 changed files with 20 additions and 3 deletions
|
@ -1,6 +1,5 @@
|
|||
import { error } from "@sveltejs/kit";
|
||||
import { building } from "$app/environment";
|
||||
import type { LayoutServerLoad } from "./$types";
|
||||
import type { APIError } from "$lib/api/entities";
|
||||
import { apiFetch } from "$lib/api/fetch";
|
||||
import type { MetaResponse } from "$lib/api/responses";
|
||||
|
||||
|
@ -8,6 +7,24 @@ export const load = (async () => {
|
|||
try {
|
||||
return await apiFetch<MetaResponse>("/meta", {});
|
||||
} catch (e) {
|
||||
throw error(500, (e as APIError).message);
|
||||
console.warn("error fetching meta endpoint:", e);
|
||||
|
||||
if (building) {
|
||||
// just return an empty object--this only affects the three static pages, nothing else, so it's fine
|
||||
return {
|
||||
git_repository: "",
|
||||
git_commit: "",
|
||||
users: {
|
||||
total: 0,
|
||||
active_month: 0,
|
||||
active_week: 0,
|
||||
active_day: 0,
|
||||
},
|
||||
members: 0,
|
||||
require_invite: false,
|
||||
};
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}) satisfies LayoutServerLoad;
|
||||
|
|
Loading…
Reference in a new issue