diff --git a/src/utils/echo.js b/src/utils/echo.js index 298f42e..1677605 100644 --- a/src/utils/echo.js +++ b/src/utils/echo.js @@ -20,9 +20,11 @@ function getToken() { return null; } -function apiOrigin() { - const url = import.meta.env.VITE_API_URL || "https://mm.com.tm/api/v1/"; - return url.replace(/\/?api\/v1\/?$/, ""); +function apiUrl(path) { + const base = import.meta.env.VITE_API_URL || "https://mm.com.tm/api/v1/"; + const normalized = base.endsWith("/") ? base : `${base}/`; + + return `${normalized}${String(path).replace(/^\//, "")}`; } function isLoopbackHost(host) { @@ -83,11 +85,12 @@ export function getChatEcho() { enabledTransports: ["ws", "wss"], disableStats: true, Pusher, - authEndpoint: `${apiOrigin()}/broadcasting/auth`, + authEndpoint: apiUrl("broadcasting/auth"), auth: { headers: { Authorization: `Bearer ${token}`, Accept: "application/json", + "Api-Token": import.meta.env.VITE_API_TOKEN || "hello-mf-s", }, }, });