import axios from "axios"; window.axios = axios; window.axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest"; import Echo from "laravel-echo"; import Pusher from "pusher-js"; window.Pusher = Pusher; /** * 根据当前页面环境自动检测 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; window.Echo = new Echo({ broadcaster: "reverb", key: import.meta.env.VITE_REVERB_APP_KEY, wsHost: wsHost, wsPort: isSecure ? 443 : (import.meta.env.VITE_REVERB_PORT ?? 8080), wssPort: isSecure ? 443 : (import.meta.env.VITE_REVERB_PORT ?? 443), forceTLS: isSecure, enabledTransports: ["ws", "wss"], });