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.

22 lines
843 B

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