From 5fdc2d4374f97d0acd536c860bd75225721447c7 Mon Sep 17 00:00:00 2001 From: hanif salafi Date: Fri, 10 Apr 2026 18:59:01 +0700 Subject: [PATCH] feat: fixing build npm --- Dockerfile | 2 +- lib/public-api.ts | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3a4494e..4abef36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM node:20-alpine # Mengatur port -ENV PORT 3000 +ENV PORT=3000 # Install pnpm secara global RUN npm install -g pnpm diff --git a/lib/public-api.ts b/lib/public-api.ts index 14e8011..d4d9a4a 100644 --- a/lib/public-api.ts +++ b/lib/public-api.ts @@ -14,14 +14,19 @@ export async function publicFetch(path: string): Promise { const base = apiBase(); if (!base) return null; const url = `${base}${path.startsWith("/") ? path : `/${path}`}`; - const res = await fetch(url, { - headers: { - "Content-Type": "application/json", - "X-Client-Key": clientKey(), - }, - next: { revalidate: 60 }, - }); - if (!res.ok) return null; - const json = (await res.json()) as { data?: T }; - return json.data ?? null; + try { + const res = await fetch(url, { + headers: { + "Content-Type": "application/json", + "X-Client-Key": clientKey(), + }, + next: { revalidate: 60 }, + }); + if (!res.ok) return null; + const json = (await res.json()) as { data?: T }; + return json.data ?? null; + } catch { + // e.g. ECONNREFUSED during `next build` in Docker when API is not running + return null; + } }