Refactor API URL handling in echo.js to improve path normalization and enhance auth endpoint configuration. Updated apiOrigin to apiUrl for better flexibility and added support for an optional API token in headers.
This commit is contained in:
@@ -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",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user