From b9993bd29e46eb7040fbac768efa8bcd26a46cdc Mon Sep 17 00:00:00 2001 From: ralksta Date: Sun, 8 Mar 2026 21:38:44 +0100 Subject: [PATCH] fix: gracefully handle Next.js static component fetch rendering when setup configs are completely empty --- app/page.tsx | 5 +++++ lib/config/index.ts | 2 +- lib/env.ts | 16 +++------------- lib/immich.ts | 7 ++++--- server.log | 6 ++++++ 5 files changed, 19 insertions(+), 17 deletions(-) create mode 100644 server.log diff --git a/app/page.tsx b/app/page.tsx index b6195cb..b3bc1d1 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -41,6 +41,11 @@ function HeroNavLinks({ export default async function HomePage() { const config = getConfig(); + + if (config.needsSetup) { + return null; + } + const [subpages, albums] = await Promise.all([ immich.getSubpages(), immich.getStandaloneAlbums(), diff --git a/lib/config/index.ts b/lib/config/index.ts index 3781eba..2f6b330 100644 --- a/lib/config/index.ts +++ b/lib/config/index.ts @@ -22,7 +22,7 @@ export function getConfig(): AppConfig { const gallery = loadYaml('gallery.yaml'); const settings = loadYaml('settings.yaml') || {}; - if (!gallery) { + if (!gallery || !apiKey || !apiUrl) { // Return dummy config if gallery.yaml is missing _config = { immich: { apiUrl: `${apiUrl}/api`, apiKey }, diff --git a/lib/env.ts b/lib/env.ts index d052f3e..f2dd0e6 100644 --- a/lib/env.ts +++ b/lib/env.ts @@ -18,25 +18,15 @@ function parseEnv(): Env { const urlRaw = process.env.IMMICH_API_URL; let apiUrl = ''; - if (!urlRaw) { - errors.push('IMMICH_API_URL is required'); - } else { + if (urlRaw) { try { apiUrl = new URL(urlRaw).toString().replace(/\/+$/, ''); } catch { - errors.push('IMMICH_API_URL must be a valid URL'); + console.warn('⚠️ IMMICH_API_URL is invalid, falling back to empty string for setup.'); } } - const apiKey = process.env.IMMICH_API_KEY; - if (!apiKey) { - errors.push('IMMICH_API_KEY is required'); - } - - if (errors.length > 0) { - const formatted = errors.map((err) => ` ✗ ${err}`).join('\n'); - throw new Error(`\n❌ Environment validation failed:\n${formatted}\n`); - } + const apiKey = process.env.IMMICH_API_KEY || ''; const cacheTtlStr = process.env.CACHE_TTL; const cacheTtl = cacheTtlStr && !isNaN(parseInt(cacheTtlStr, 10)) ? parseInt(cacheTtlStr, 10) : 300; diff --git a/lib/immich.ts b/lib/immich.ts index 33aacce..b980fc7 100644 --- a/lib/immich.ts +++ b/lib/immich.ts @@ -78,10 +78,9 @@ class ImmichClient { return getConfig(); } - /** - * Make an authenticated request to the Immich API. - */ private async request(endpoint: string): Promise { + if (this.config.needsSetup) return null; + const url = `${this.config.immich.apiUrl}${endpoint}`; try { const res = await fetch(url, { @@ -114,6 +113,8 @@ class ImmichClient { assetId: string, size: ImageSize = 'preview', ): Promise<{ stream: ReadableStream; contentType: string; contentLength: string | null } | null> { + if (this.config.needsSetup || !this.config.immich.apiUrl) return null; + const endpoint = size === 'original' ? `/assets/${encodeURIComponent(assetId)}/original` diff --git a/server.log b/server.log new file mode 100644 index 0000000..1375a52 --- /dev/null +++ b/server.log @@ -0,0 +1,6 @@ +▲ Next.js 16.1.6 +- Local: http://localhost:3000 +- Network: http://0.0.0.0:3000 + +✓ Starting... +✓ Ready in 33ms