fix: gracefully handle Next.js static component fetch rendering when setup configs are completely empty

This commit is contained in:
ralksta
2026-03-08 21:38:44 +01:00
parent 89bb7c0038
commit b9993bd29e
5 changed files with 19 additions and 17 deletions

View File

@@ -41,6 +41,11 @@ function HeroNavLinks({
export default async function HomePage() { export default async function HomePage() {
const config = getConfig(); const config = getConfig();
if (config.needsSetup) {
return null;
}
const [subpages, albums] = await Promise.all([ const [subpages, albums] = await Promise.all([
immich.getSubpages(), immich.getSubpages(),
immich.getStandaloneAlbums(), immich.getStandaloneAlbums(),

View File

@@ -22,7 +22,7 @@ export function getConfig(): AppConfig {
const gallery = loadYaml<GalleryYaml>('gallery.yaml'); const gallery = loadYaml<GalleryYaml>('gallery.yaml');
const settings = loadYaml<SettingsYaml>('settings.yaml') || {}; const settings = loadYaml<SettingsYaml>('settings.yaml') || {};
if (!gallery) { if (!gallery || !apiKey || !apiUrl) {
// Return dummy config if gallery.yaml is missing // Return dummy config if gallery.yaml is missing
_config = { _config = {
immich: { apiUrl: `${apiUrl}/api`, apiKey }, immich: { apiUrl: `${apiUrl}/api`, apiKey },

View File

@@ -18,25 +18,15 @@ function parseEnv(): Env {
const urlRaw = process.env.IMMICH_API_URL; const urlRaw = process.env.IMMICH_API_URL;
let apiUrl = ''; let apiUrl = '';
if (!urlRaw) { if (urlRaw) {
errors.push('IMMICH_API_URL is required');
} else {
try { try {
apiUrl = new URL(urlRaw).toString().replace(/\/+$/, ''); apiUrl = new URL(urlRaw).toString().replace(/\/+$/, '');
} catch { } 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; 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 cacheTtlStr = process.env.CACHE_TTL; const cacheTtlStr = process.env.CACHE_TTL;
const cacheTtl = cacheTtlStr && !isNaN(parseInt(cacheTtlStr, 10)) ? parseInt(cacheTtlStr, 10) : 300; const cacheTtl = cacheTtlStr && !isNaN(parseInt(cacheTtlStr, 10)) ? parseInt(cacheTtlStr, 10) : 300;

View File

@@ -78,10 +78,9 @@ class ImmichClient {
return getConfig(); return getConfig();
} }
/**
* Make an authenticated request to the Immich API.
*/
private async request<T>(endpoint: string): Promise<T | null> { private async request<T>(endpoint: string): Promise<T | null> {
if (this.config.needsSetup) return null;
const url = `${this.config.immich.apiUrl}${endpoint}`; const url = `${this.config.immich.apiUrl}${endpoint}`;
try { try {
const res = await fetch(url, { const res = await fetch(url, {
@@ -114,6 +113,8 @@ class ImmichClient {
assetId: string, assetId: string,
size: ImageSize = 'preview', size: ImageSize = 'preview',
): Promise<{ stream: ReadableStream; contentType: string; contentLength: string | null } | null> { ): Promise<{ stream: ReadableStream; contentType: string; contentLength: string | null } | null> {
if (this.config.needsSetup || !this.config.immich.apiUrl) return null;
const endpoint = const endpoint =
size === 'original' size === 'original'
? `/assets/${encodeURIComponent(assetId)}/original` ? `/assets/${encodeURIComponent(assetId)}/original`

6
server.log Normal file
View File

@@ -0,0 +1,6 @@
▲ Next.js 16.1.6
- Local: http://localhost:3000
- Network: http://0.0.0.0:3000
✓ Starting...
✓ Ready in 33ms