From 93b8adf55d7df6aee4fafc03a75cecc24eae5186 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Tue, 19 May 2026 19:26:58 +0300 Subject: [PATCH 1/2] fix: require PB_URL in production, fall back to localhost in dev only Co-Authored-By: Claude Sonnet 4.6 --- src/shared/api/client.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/shared/api/client.ts b/src/shared/api/client.ts index 5572351..c2bd376 100644 --- a/src/shared/api/client.ts +++ b/src/shared/api/client.ts @@ -4,10 +4,8 @@ import type { ListResponse } from './types'; * Native fetch wrapper for PocketBase API requests. */ -/* Prefer the server-only var (not exposed to the browser bundle), - * fall back to the public var for client-side usage, then to the - * local dev default. */ -const PB_URL = process.env.PB_URL ?? process.env.NEXT_PUBLIC_PB_URL ?? 'http://127.0.0.1:8090'; +/* Required in production; falls back to localhost in development. */ +const PB_URL = process.env.PB_URL ?? (process.env.NODE_ENV === 'development' ? 'http://127.0.0.1:8090' : undefined); /** * Options for PocketBase collection fetching. @@ -43,6 +41,10 @@ export type PBFetchOptions = { export async function getCollection(collection: string, options: PBFetchOptions = {}): Promise> { const { sort, filter, expand, tags, revalidate } = options; + if (!PB_URL) { + throw new Error('PB_URL is required in production'); + } + const params = new URLSearchParams(); if (sort) { params.set('sort', sort); -- 2.52.0 From 6b15a0e65899faa6e914f06a0393bbec124000b8 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Tue, 19 May 2026 19:27:04 +0300 Subject: [PATCH 2/2] fix: gracefully handle PocketBase unreachable during static generation Co-Authored-By: Claude Sonnet 4.6 --- app/[[...slug]]/page.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/[[...slug]]/page.tsx b/app/[[...slug]]/page.tsx index 6cc7a73..4fa0ef0 100644 --- a/app/[[...slug]]/page.tsx +++ b/app/[[...slug]]/page.tsx @@ -8,11 +8,15 @@ import { SectionsAccordion } from '$widgets/SectionsAccordion'; * Optional catchall: `/` → first section, `/:slug` → that section. */ export async function generateStaticParams() { - const { items: sections } = await getCollection('sections', { - sort: 'order', - tags: ['sections'], - }); - return [{}, ...sections.map((s) => ({ slug: [s.slug] }))]; + try { + const { items: sections } = await getCollection('sections', { + sort: 'order', + }); + return [{}, ...sections.map((s) => ({ slug: [s.slug] }))]; + } catch (err) { + console.warn('[generateStaticParams] PocketBase unreachable at build — deferring to runtime ISR', err); + return []; + } } type Props = { -- 2.52.0