feat: makes nextjs able to access backend in chromium
This commit is contained in:
parent
e79c64ec21
commit
ac59114208
1 changed files with 15 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue