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.

26 lines
993 B

7 months ago
1 month ago
1 month ago
1 month 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 = window.location.host;
  9. const host = "127.0.0.1";
  10. // const port = '8082' // 使用固定的后端端口;由于本地开发时,8080被占用导致ws连接失败,所以使用8082
  11. const port = "80"
  12. // 构建 WebSocket URL
  13. const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
  14. const wsUrl = `${wsProtocol}//${host}:${port}${wsPath}`
  15. // const wsUrl = `${wsProtocol}//${host}${wsPath}`
  16. // 构建 HTTP URL
  17. const httpUrl = `${window.location.protocol}//${host}:${port}` // 例如: "http://192.168.1.100:8082" 或 "http://localhost:8082"
  18. return {
  19. wsUrl,
  20. httpUrl,
  21. host,
  22. port,
  23. }
  24. }