feat: makes nextjs able to access backend in chromium

This commit is contained in:
sauravniraula 2026-03-10 19:28:05 +05:45
parent e79c64ec21
commit ac59114208
No known key found for this signature in database
GPG key ID: 60FCC1B5A5E83326

View file

@ -5,18 +5,22 @@ export function getFastAPIUrl(): string {
return (window as any).env.NEXT_PUBLIC_FAST_API || '';
}
// Check if we're running in Electron vs Docker/web mode
if (typeof window !== 'undefined' && (window as any).electron) {
// Electron mode: direct access to FastAPI
return process.env.NEXT_PUBLIC_FAST_API || 'http://127.0.0.1:8000';
} else {
// Docker/web mode: use current origin (goes through nginx)
if (typeof window !== 'undefined') {
return window.location.origin;
}
// Server-side fallback
return process.env.NEXT_PUBLIC_FAST_API || 'http://127.0.0.1:8000';
// Prefer explicit env var when available in any mode
if (process.env.NEXT_PUBLIC_FAST_API) {
return process.env.NEXT_PUBLIC_FAST_API;
}
// Electron mode: direct access to FastAPI
if (typeof window !== 'undefined' && (window as any).electron) {
return 'http://127.0.0.1:8000';
}
// Docker/web mode: use current origin (goes through nginx)
if (typeof window !== 'undefined') {
return window.location.origin;
}
// Server-side fallback
return 'http://127.0.0.1:8000';
}
// Utility to construct full API URL