Merge pull request 'fix: require PB_URL in production, fall back to localhost in dev only' (#5) from fix/pocketbase into main
Build and push / build (push) Failing after 1m10s

Reviewed-on: #5
This commit was merged in pull request #5.
This commit is contained in:
2026-05-19 16:28:43 +00:00
2 changed files with 15 additions and 9 deletions
+5 -1
View File
@@ -8,11 +8,15 @@ import { SectionsAccordion } from '$widgets/SectionsAccordion';
* Optional catchall: `/` → first section, `/:slug` → that section.
*/
export async function generateStaticParams() {
try {
const { items: sections } = await getCollection<SectionRecord>('sections', {
sort: 'order',
tags: ['sections'],
});
return [{}, ...sections.map((s) => ({ slug: [s.slug] }))];
} catch (err) {
console.warn('[generateStaticParams] PocketBase unreachable at build — deferring to runtime ISR', err);
return [];
}
}
type Props = {
+6 -4
View File
@@ -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<T>(collection: string, options: PBFetchOptions = {}): Promise<ListResponse<T>> {
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);