2026-02-26 13:35:38 +08:00
|
|
|
|
import axios from "axios";
|
2026-02-26 12:02:00 +08:00
|
|
|
|
window.axios = axios;
|
|
|
|
|
|
|
2026-02-26 13:35:38 +08:00
|
|
|
|
window.axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
|
|
|
|
|
|
|
|
|
|
|
|
import Echo from "laravel-echo";
|
|
|
|
|
|
import Pusher from "pusher-js";
|
|
|
|
|
|
|
|
|
|
|
|
window.Pusher = Pusher;
|
|
|
|
|
|
|
2026-02-26 21:10:34 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 根据当前页面环境自动检测 WebSocket 连接参数
|
|
|
|
|
|
*
|
|
|
|
|
|
* - 当页面通过 HTTPS 访问时,自动使用 wss:// 协议和当前域名
|
|
|
|
|
|
* - 当页面通过 HTTP 访问(本地开发)时,使用 .env 中的 Reverb 配置
|
|
|
|
|
|
*/
|
|
|
|
|
|
const isSecure = window.location.protocol === "https:";
|
|
|
|
|
|
const wsHost =
|
|
|
|
|
|
import.meta.env.VITE_REVERB_HOST &&
|
|
|
|
|
|
import.meta.env.VITE_REVERB_HOST !== "127.0.0.1" &&
|
|
|
|
|
|
import.meta.env.VITE_REVERB_HOST !== "localhost"
|
|
|
|
|
|
? import.meta.env.VITE_REVERB_HOST
|
|
|
|
|
|
: window.location.hostname;
|
|
|
|
|
|
|
2026-02-26 13:35:38 +08:00
|
|
|
|
window.Echo = new Echo({
|
|
|
|
|
|
broadcaster: "reverb",
|
|
|
|
|
|
key: import.meta.env.VITE_REVERB_APP_KEY,
|
2026-02-26 21:10:34 +08:00
|
|
|
|
wsHost: wsHost,
|
|
|
|
|
|
wsPort: isSecure ? 443 : (import.meta.env.VITE_REVERB_PORT ?? 8080),
|
|
|
|
|
|
wssPort: isSecure ? 443 : (import.meta.env.VITE_REVERB_PORT ?? 443),
|
|
|
|
|
|
forceTLS: isSecure,
|
2026-02-26 13:35:38 +08:00
|
|
|
|
enabledTransports: ["ws", "wss"],
|
|
|
|
|
|
});
|