WIP
This commit is contained in:
1 parent
6956b93701
commit
53cb864863
2 files changed
+32
-6
No files matched your search
+5
-3
@@ -1,6 +1,8 @@
|
|||||||
VITE_API_URL=https://mm.com.tm/api/v1/
|
VITE_API_URL=https://mm.com.tm/api/v1/
|
||||||
VITE_API_TOKEN=hello-mf-s
|
VITE_API_TOKEN=hello-mf-s
|
||||||
VITE_REVERB_APP_KEY=
|
VITE_REVERB_APP_KEY=
|
||||||
VITE_REVERB_HOST=127.0.0.1
|
# Production (nginx proxies /app → Reverb on 127.0.0.1:8080):
|
||||||
VITE_REVERB_PORT=8080
|
VITE_REVERB_HOST=mm.com.tm
|
||||||
VITE_REVERB_SCHEME=http
|
VITE_REVERB_PORT=443
|
||||||
|
VITE_REVERB_SCHEME=https
|
||||||
|
# Local: VITE_REVERB_HOST=127.0.0.1 VITE_REVERB_PORT=8080 VITE_REVERB_SCHEME=http
|
||||||
+27
-3
@@ -25,6 +25,32 @@ function apiOrigin() {
|
|||||||
return url.replace(/\/?api\/v1\/?$/, "");
|
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() {
|
export function getChatEcho() {
|
||||||
const key = import.meta.env.VITE_REVERB_APP_KEY;
|
const key = import.meta.env.VITE_REVERB_APP_KEY;
|
||||||
const token = getToken();
|
const token = getToken();
|
||||||
@@ -44,9 +70,7 @@ export function getChatEcho() {
|
|||||||
|
|
||||||
window.Pusher = Pusher;
|
window.Pusher = Pusher;
|
||||||
|
|
||||||
const scheme = import.meta.env.VITE_REVERB_SCHEME || "http";
|
const { host, scheme, port } = reverbEndpoint();
|
||||||
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";
|
|
||||||
|
|
||||||
echoToken = token;
|
echoToken = token;
|
||||||
echoClient = new Echo({
|
echoClient = new Echo({
|
||||||
|
|||||||
Reference in new issue
Block a user