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

如何实现跨域? #479

Open
Sweetli1415926 opened this issue Apr 30, 2023 · 4 comments
Open

如何实现跨域? #479

Sweetli1415926 opened this issue Apr 30, 2023 · 4 comments
Assignees
Labels

Comments

@Sweetli1415926
Copy link

Sweetli1415926 commented Apr 30, 2023

关于跨域的相关配置
github上代码已经更新了,文档没有更新,代码中没有了文档中的proxy.ts
我在调试时为了实现跨域,在env中

VITE_IS_REQUEST_PROXY = true
VITE_API_URL =/path

然后在vite.config.ts中
server: {
proxy: {
"/path": {
target: "https://xxx.xxx.com",
changeOrigin: true,
rewrite: (path)=> path.replace(/^/path/, ''), //这里的正则我时复制官网的,粘贴到issue中少了斜杠 这里肯定没错
},
},
//跨域请求
export function test() {
return request.get({
url: '/api/movie/xxx....xxxx....',
});
}
最后实际发送请求的时候并没有通过代理把/path替换成proxy.target
实际请求的连接时 “/path/api/movie/xxx....xx..."

@github-actions
Copy link
Contributor

👋 @Sweetli1415926,感谢给 TDesign 提出了 issue。
请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

@github-actions
Copy link
Contributor

github-actions bot commented Apr 30, 2023

♥️ 有劳 @PengYYYYY 尽快确认问题。
确认有效后将下一步计划和可能需要的时间回复给 @Sweetli1415926

@timi137137
Copy link
Collaborator

文档没更新吗...抱歉疏忽了
因为 pr #445 的缘故原有的proxy.ts被写死到了环境变量
文档这边这两天会更新

@timi137137 timi137137 added the 🏃🏻 in progress in progress label Apr 30, 2023
@Sweetli1415926
Copy link
Author

我就是还想问下更新了如何实现请求代理,我像上文那样配置 不能成功

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants