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:
1 parent
347ec3536d
commit
d6d5dd785d
1 file changed
+7
-4
+7
-4
@@ -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