WIP
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
VITE_API_URL=https://mm.com.tm/api/v1/
|
||||
VITE_API_TOKEN=hello-mf-s
|
||||
VITE_REVERB_APP_KEY=
|
||||
VITE_REVERB_HOST=127.0.0.1
|
||||
VITE_REVERB_PORT=8080
|
||||
VITE_REVERB_SCHEME=http
|
||||
# Production (nginx proxies /app → Reverb on 127.0.0.1:8080):
|
||||
VITE_REVERB_HOST=mm.com.tm
|
||||
VITE_REVERB_PORT=443
|
||||
VITE_REVERB_SCHEME=https
|
||||
# Local: VITE_REVERB_HOST=127.0.0.1 VITE_REVERB_PORT=8080 VITE_REVERB_SCHEME=http
|
||||
|
||||
@@ -25,6 +25,32 @@ function apiOrigin() {
|
||||
return url.replace(/\/?api\/v1\/?$/, "");
|
||||
}
|
||||
|
||||
function isLoopbackHost(host) {
|
||||
return !host || host === "127.0.0.1" || host === "localhost" || host === "0.0.0.0";
|
||||
}
|
||||
|
||||
function reverbEndpoint() {
|
||||
const envHost = import.meta.env.VITE_REVERB_HOST;
|
||||
const envScheme = import.meta.env.VITE_REVERB_SCHEME;
|
||||
const envPort = import.meta.env.VITE_REVERB_PORT;
|
||||
|
||||
if (import.meta.env.PROD && isLoopbackHost(envHost)) {
|
||||
const https = window.location.protocol === "https:";
|
||||
return {
|
||||
host: window.location.hostname,
|
||||
scheme: https ? "https" : "http",
|
||||
port: https ? 443 : 80,
|
||||
};
|
||||
}
|
||||
|
||||
const scheme = envScheme || "http";
|
||||
return {
|
||||
host: envHost || "127.0.0.1",
|
||||
scheme,
|
||||
port: Number(envPort || (scheme === "https" ? 443 : 8080)),
|
||||
};
|
||||
}
|
||||
|
||||
export function getChatEcho() {
|
||||
const key = import.meta.env.VITE_REVERB_APP_KEY;
|
||||
const token = getToken();
|
||||
@@ -44,9 +70,7 @@ export function getChatEcho() {
|
||||
|
||||
window.Pusher = Pusher;
|
||||
|
||||
const scheme = import.meta.env.VITE_REVERB_SCHEME || "http";
|
||||
const port = Number(import.meta.env.VITE_REVERB_PORT || (scheme === "https" ? 443 : 8080));
|
||||
const host = import.meta.env.VITE_REVERB_HOST || "127.0.0.1";
|
||||
const { host, scheme, port } = reverbEndpoint();
|
||||
|
||||
echoToken = token;
|
||||
echoClient = new Echo({
|
||||
|
||||
Reference in New Issue
Block a user