我正在学习 Angular,当我尝试使用代理时,仍然得到index.html
我使用如下代理
{
"/api/*": {
"target": "http://localhost:8080/v1/api/playground",
"secure": false,
"pathRewrite": {
"^/api": ""
},
"changeOrigin": true,
"logLevel": "debug"
}
}
我的请求如下,发送请求,其中
playgroundId
是uuid,但我仍然收到index.html
作为响应
private apiUrl = '/api/playground/';
const response = await fetch(this.apiUrl + this.playgroundId);
当我尝试发送另一个请求时,如下所示,我收到 json 响应。
private apiUrl = '/api/playgrounds';
const response = await fetch(this.apiUrl);
` 它返回 json 作为响应。
我检查了服务器中的日志,如果有 1 个请求,服务器不会收到它,但如果有 2 个请求,服务器会收到请求。
如有任何帮助,我们将不胜感激
!!我现在不想更改服务器端的 CORS 策略!!
将 proxy.conf.json 更改为:
{
"/api/**": {
"target": "http://localhost:8080/v1/api/playground",
"secure": false,
"pathRewrite": {
"^/api": ""
},
"changeOrigin": true,
"logLevel": "debug"
}
}
使用两颗星而不是一颗星。这对我从 v16 到 v17 都有效。感谢我的朋友 @marktechson,他是 Angular 团队的成员,帮助我解决了这个问题。