Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): normalize API base URLs

Tind561804689e4
diff --git a/apps/web/src/fetchers/get-api-url.ts b/apps/web/src/fetchers/get-api-url.ts
index 2794ef835..e6a636369 100644
--- a/apps/web/src/fetchers/get-api-url.ts
+++ b/apps/web/src/fetchers/get-api-url.ts
@@ -1,6 +1,11 @@
export function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
+ const trimmedBase = (
+ import.meta.env.VITE_API_URL || "http://localhost:1337"
+ ).replace(/\/+$/, "");
+ const apiUrl = trimmedBase.endsWith("/api")
+ ? trimmedBase
+ : `${trimmedBase}/api`;
+ const normalizedPath = `/${path.replace(/^\/+/, "")}`;
- return `${apiUrl}${path}`;
+ return `${apiUrl}${normalizedPath}`;
}