Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: socket errors #192

Merged
merged 2 commits into from
Dec 17, 2023
Merged

fix: socket errors #192

merged 2 commits into from
Dec 17, 2023

Conversation

poboll
Copy link
Contributor

@poboll poboll commented Dec 17, 2023

Pull Request Template

constructor() {
  // 如果 GATEWAY_URL 已经包含斜杠,确保它不以斜杠结尾
  const gatewayUrlWithoutTrailingSlash = GATEWAY_URL.replace(/\/$/, '');

  // 拼接路径
  this.socket = io(`${gatewayUrlWithoutTrailingSlash}/web`, {
    timeout: 10000,
    reconnectionDelay: 3000,
    autoConnect: false,
    reconnectionAttempts: 3,
    transports: ['websocket'],
  });
}

Description

由于环境变量GATEWAYURL地址末尾多加了个/导致的Socket连接失败

错误信息

无法正常显示网页在线人数
Socket.io connection error: Invalid namespace.

排查过程

前端由Vercel直接Fork部署、
服务端首先检查nginx的配置文件,反向代理支持socket连接、WebSocket 在线测试工具测试相关配置都没问题后
根据浏览器的抓包数据,发现路径多添加了一个/,已针对修复。

50e2a292810bea0004cdcb40889b155f

Linked Issues

Additional context

添加对shocket路径的检查GATEWAY_URL的检查,并对其进行适当处理。
已测试正常

image

Signed-off-by: poboll <caiths@icloud.com>
Copy link

vercel bot commented Dec 17, 2023

Someone is attempting to deploy a commit to a Personal Account owned by @Innei on Vercel.

@Innei first needs to authorize it.

@Innei
Copy link
Owner

Innei commented Dec 17, 2023

3Q for your contribution

@Innei Innei merged commit 95ae696 into Innei:main Dec 17, 2023
1 of 2 checks passed
@poboll poboll deleted the pr branch December 17, 2023 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants