Compare commits

..

2 Commits

Author SHA1 Message Date
Ilia Mashkov 6b15a0e658 fix: gracefully handle PocketBase unreachable during static generation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 19:27:04 +03:00
Ilia Mashkov 93b8adf55d fix: require PB_URL in production, fall back to localhost in dev only
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 19:26:58 +03:00
2 changed files with 15 additions and 9 deletions
+9 -5
View File
@@ -8,11 +8,15 @@ import { SectionsAccordion } from '$widgets/SectionsAccordion';
* Optional catchall: `/` → first section, `/:slug` → that section. * Optional catchall: `/` → first section, `/:slug` → that section.
*/ */
export async function generateStaticParams() { export async function generateStaticParams() {
const { items: sections } = await getCollection<SectionRecord>('sections', { try {
sort: 'order', const { items: sections } = await getCollection<SectionRecord>('sections', {
tags: ['sections'], sort: 'order',
}); });
return [{}, ...sections.map((s) => ({ slug: [s.slug] }))]; return [{}, ...sections.map((s) => ({ slug: [s.slug] }))];
} catch (err) {
console.warn('[generateStaticParams] PocketBase unreachable at build — deferring to runtime ISR', err);
return [];
}
} }
type Props = { type Props = {
+6 -4
View File
@@ -4,10 +4,8 @@ import type { ListResponse } from './types';
* Native fetch wrapper for PocketBase API requests. * Native fetch wrapper for PocketBase API requests.
*/ */
/* Prefer the server-only var (not exposed to the browser bundle), /* Required in production; falls back to localhost in development. */
* fall back to the public var for client-side usage, then to the const PB_URL = process.env.PB_URL ?? (process.env.NODE_ENV === 'development' ? 'http://127.0.0.1:8090' : undefined);
* local dev default. */
const PB_URL = process.env.PB_URL ?? process.env.NEXT_PUBLIC_PB_URL ?? 'http://127.0.0.1:8090';
/** /**
* Options for PocketBase collection fetching. * Options for PocketBase collection fetching.
@@ -43,6 +41,10 @@ export type PBFetchOptions = {
export async function getCollection<T>(collection: string, options: PBFetchOptions = {}): Promise<ListResponse<T>> { export async function getCollection<T>(collection: string, options: PBFetchOptions = {}): Promise<ListResponse<T>> {
const { sort, filter, expand, tags, revalidate } = options; const { sort, filter, expand, tags, revalidate } = options;
if (!PB_URL) {
throw new Error('PB_URL is required in production');
}
const params = new URLSearchParams(); const params = new URLSearchParams();
if (sort) { if (sort) {
params.set('sort', sort); params.set('sort', sort);