docker setup

This commit is contained in:
2025-12-26 18:59:50 +01:00
parent 64377de548
commit 904feb41b8
11 changed files with 198 additions and 30 deletions

View File

@@ -0,0 +1,36 @@
function normalizeBaseUrl(raw: string): string {
const trimmed = raw.trim();
return trimmed.endsWith('/') ? trimmed.slice(0, -1) : trimmed;
}
export function getWebsiteApiBaseUrl(): string {
const isBrowser = typeof window !== 'undefined';
const configured = isBrowser
? process.env.NEXT_PUBLIC_API_BASE_URL
: process.env.API_BASE_URL ?? process.env.NEXT_PUBLIC_API_BASE_URL;
if (configured && configured.trim()) {
return normalizeBaseUrl(configured);
}
const isTestLike =
process.env.NODE_ENV === 'test' ||
process.env.CI === 'true' ||
process.env.DOCKER === 'true';
if (isTestLike) {
throw new Error(
isBrowser
? 'Missing NEXT_PUBLIC_API_BASE_URL. In Docker/CI/test we do not allow falling back to localhost.'
: 'Missing API_BASE_URL. In Docker/CI/test we do not allow falling back to localhost.',
);
}
const fallback =
process.env.NODE_ENV === 'development'
? 'http://localhost:3001'
: 'http://api:3000';
return normalizeBaseUrl(fallback);
}