A8000
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
904 B

7 months ago
7 months ago
7 months ago
  1. export function getServerInfo(wsPath: string = '/api/v1/app/ws/state') {
  2. // 获取当前页面的 URL 对象
  3. // @ts-ignore
  4. const url = new URL(window.location.href)
  5. // 获取主机名(IP 或域名)和端口号
  6. // const host = url.hostname // 例如: "192.168.1.100" 或 "localhost"
  7. // const host = window.location.hostname;
  8. const host = "192.168.1.119";
  9. // const port = '8082' // 使用固定的后端端口;由于本地开发时,8080被占用导致ws连接失败,所以使用8082
  10. const port = "80"
  11. // 构建 WebSocket URL
  12. const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
  13. const wsUrl = `${wsProtocol}//${host}:${port}${wsPath}`
  14. // 构建 HTTP URL
  15. const httpUrl = `${window.location.protocol}//${host}:${port}` // 例如: "http://192.168.1.100:8082" 或 "http://localhost:8082"
  16. return {
  17. wsUrl,
  18. httpUrl,
  19. host,
  20. port,
  21. }
  22. }