muhammadpriv001's picture
fix: use getApiUrl in frontend for direct cross-origin API calls without proxy payload stripping
d585643
Raw History Blame Contribute Delete
669 Bytes
export function getApiUrl(path: string): string {
const envUrl = process.env.NEXT_PUBLIC_API_URL || "";
const cleanBase = envUrl.trim().replace(/\/+$/, "");
const cleanPath = path.startsWith("/") ? path : `/${path}`;
if (cleanBase) {
// Direct cross-origin request to backend (bypasses Next.js proxy body mangling)
const apiPrefix = cleanPath.startsWith("/api") ? cleanPath : `/api${cleanPath}`;
return `${cleanBase}${apiPrefix}`;
}
// Fallback to relative path using Next.js rewrite
const backendPrefix = cleanPath.startsWith("/backend-api")
? cleanPath
: `/backend-api${cleanPath.replace(/^\/api/, "")}`;
return backendPrefix;
}