Pavanupadhyay27 commited on
Commit ·
afd6f8b
1
Parent(s): b1302c4
Auto-append /api/v1 prefix to getBackendUrl in frontend
Browse files
frontend/app/utils/api.ts
CHANGED
|
@@ -3,7 +3,14 @@ const DEFAULT_BACKEND_URL = "http://localhost:8000/api/v1";
|
|
| 3 |
export function getBackendUrl(): string {
|
| 4 |
// Check for environment variable configuration (e.g. on Vercel)
|
| 5 |
if (process.env.NEXT_PUBLIC_API_URL) {
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
}
|
| 8 |
if (typeof window !== "undefined") {
|
| 9 |
const host = window.location.hostname;
|
|
|
|
| 3 |
export function getBackendUrl(): string {
|
| 4 |
// Check for environment variable configuration (e.g. on Vercel)
|
| 5 |
if (process.env.NEXT_PUBLIC_API_URL) {
|
| 6 |
+
let url = process.env.NEXT_PUBLIC_API_URL.trim();
|
| 7 |
+
if (url.endsWith("/")) {
|
| 8 |
+
url = url.slice(0, -1);
|
| 9 |
+
}
|
| 10 |
+
if (!url.endsWith("/api/v1")) {
|
| 11 |
+
url = `${url}/api/v1`;
|
| 12 |
+
}
|
| 13 |
+
return url;
|
| 14 |
}
|
| 15 |
if (typeof window !== "undefined") {
|
| 16 |
const host = window.location.hostname;
|