presenton/servers/nextjs/utils/api.ts
sudipnext c7860127f2 feat: add support for optional embedded Ollama and enhance database migration handling
- Updated docker-compose.yml to allow disabling embedded Ollama via environment variable.
- Refactored Dockerfile and Dockerfile.dev for improved dependency management and installation process.
- Enhanced FastAPI migration scripts to handle orphaned Alembic revisions and added new database migration logic.
- Improved error handling in background tasks and Codex authentication endpoints.
- Added support for font file uploads with better validation and extraction of font names.
- Introduced new image search functionality with support for Pexels and Pixabay APIs.
2026-04-15 15:39:35 +05:45

47 lines
1.2 KiB
TypeScript

// Same-origin API and static assets: nginx proxies /api/v1, /static, /app_data to fixed internal ports.
function withLeadingSlash(path: string): string {
return path.startsWith("/") ? path : `/${path}`;
}
function isAbsoluteHttpUrl(path: string): boolean {
return /^https?:\/\//i.test(path);
}
/** Browser: current site origin. Server render: localhost FastAPI (dev only). */
export function getFastAPIUrl(): string {
if (typeof window !== "undefined") {
return window.location.origin;
}
return "http://127.0.0.1:8000";
}
/** Use relative URLs; nginx serves /api/v1 on the same host as the UI. */
export function getApiUrl(path: string): string {
if (isAbsoluteHttpUrl(path)) {
return path;
}
return withLeadingSlash(path);
}
/** Keep /static and /app_data as same-origin paths the browser resolves. */
export function resolveBackendAssetUrl(path?: string): string {
if (!path) return "";
const trimmed = path.trim();
if (!trimmed) return "";
if (
trimmed.startsWith("data:") ||
trimmed.startsWith("blob:") ||
trimmed.startsWith("file:")
) {
return trimmed;
}
if (isAbsoluteHttpUrl(trimmed)) {
return trimmed;
}
return withLeadingSlash(trimmed);
}