fix server error

This commit is contained in:
liyunze 2026-08-31 19:04:14 +08:00
parent d4527d74fd
commit f826141940
3 changed files with 18 additions and 5 deletions

View file

@ -14,6 +14,9 @@ RUN npm ci
COPY . . COPY . .
RUN npm run build RUN npm run build
# Keep only production dependencies so they can be copied into the runtime image.
RUN npm prune --omit=dev
# ---- Runtime stage ---- # ---- Runtime stage ----
FROM node:24-alpine AS runtime FROM node:24-alpine AS runtime
@ -25,6 +28,8 @@ ENV NODE_ENV=production \
DATABASE_PATH=data/dsec.db DATABASE_PATH=data/dsec.db
COPY --from=build /app/build ./build COPY --from=build /app/build ./build
COPY --from=build /app/package.json ./package.json
COPY --from=build /app/node_modules ./node_modules
RUN mkdir -p data && chown -R node:node /app RUN mkdir -p data && chown -R node:node /app
USER node USER node

View file

@ -5,9 +5,9 @@ async function call(name: string, args: Record<string, any> = {}): Promise<any>
body: JSON.stringify({ fn: name, args }), body: JSON.stringify({ fn: name, args }),
}); });
const data = await res.json(); const data = await res.json().catch(() => null);
if (!data.ok) { if (!res.ok || !data?.ok) {
throw new Error(data.error ?? "Request failed"); throw new Error(data?.error ?? `Request failed (${res.status})`);
} }
return data.result; return data.result;
} }

View file

@ -5,10 +5,16 @@
let units: UnitDoc[] = $state([]); let units: UnitDoc[] = $state([]);
let loading = $state(true); let loading = $state(true);
let error = $state("");
onMount(async () => { onMount(async () => {
try {
units = (await query("units:getAll")) as UnitDoc[]; units = (await query("units:getAll")) as UnitDoc[];
} catch (err: any) {
error = err.message ?? "Failed to load units";
} finally {
loading = false; loading = false;
}
}); });
</script> </script>
@ -38,6 +44,8 @@
<p class="kicker mb-6">Units</p> <p class="kicker mb-6">Units</p>
{#if loading} {#if loading}
<p class="kicker">Loading</p> <p class="kicker">Loading</p>
{:else if error}
<p class="kicker">{error}</p>
{:else} {:else}
<div class="grid grid-cols-1 sm:grid-cols-2"> <div class="grid grid-cols-1 sm:grid-cols-2">
{#each units as unit} {#each units as unit}