fix: gracefully handle Next.js static component fetch rendering when setup configs are completely empty
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -22,7 +22,7 @@ export function getConfig(): AppConfig {
|
||||
const gallery = loadYaml<GalleryYaml>('gallery.yaml');
|
||||
const settings = loadYaml<SettingsYaml>('settings.yaml') || {};
|
||||
|
||||
if (!gallery) {
|
||||
if (!gallery || !apiKey || !apiUrl) {
|
||||
// Return dummy config if gallery.yaml is missing
|
||||
_config = {
|
||||
immich: { apiUrl: `${apiUrl}/api`, apiKey },
|
||||
|
||||
16
lib/env.ts
16
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;
|
||||
|
||||
@@ -78,10 +78,9 @@ class ImmichClient {
|
||||
return getConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an authenticated request to the Immich API.
|
||||
*/
|
||||
private async request<T>(endpoint: string): Promise<T | null> {
|
||||
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`
|
||||
|
||||
6
server.log
Normal file
6
server.log
Normal 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
|
||||
Reference in New Issue
Block a user