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

前后端分离的情况下,wss url 拼接不在预料中 #4

Closed
hrool opened this issue Sep 23, 2022 · 1 comment
Closed

前后端分离的情况下,wss url 拼接不在预料中 #4

hrool opened this issue Sep 23, 2022 · 1 comment

Comments

@hrool
Copy link

hrool commented Sep 23, 2022

我通过修改src/config/request.ts文件使用不同的后端api地址:

const request: AxiosInstance = axios.create({
      timeout: 200000,
      headers: {
            'Content-Type': 'application/json'
      },
      baseURL: `https://api-yearning.XXXX.com/`,
})

首页地址是yearning.XXXX.com, 后端地址是api-yearning.XXXX.com

src/socket/index.ts

      constructor(prefix: string, token: string) {
            let baseURL = ""
            import.meta.env.MODE === "dev" ? baseURL = "127.0.0.1:8000" : baseURL = document.location.host

document.location.host的值和baseURL的值不相等, 导致wss的地址拼接不是预料中的情况。

@hrool hrool changed the title wss url has hardcode when use split backend api domain 前后端分离的情况下,wss url 拼接不在预料中 Sep 23, 2022
@cookieY
Copy link
Owner

cookieY commented Sep 27, 2022

更改地址 需要变更这两个地方 因为axios 仅是http请求的封装 不支持ws ws需要自己实现

@cookieY cookieY closed this as completed Jul 11, 2023
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

No branches or pull requests

2 participants