角度代理通配符无法正常工作。只适用于一条路线
我创建了一个角度代理来在开发过程中绕过 CORS。问题是,代理似乎只适用于一条路线,而不适用于其他任何路线。除了代理配置之外,还有什么我应该注意的吗?我的后端位于云上,与我的开发环境分开。
这是我的代理的配置:
{
"/api/*": {
"target": "http://x.x.x.x:3000",
"secure": false
}
}
有效的路由是 /api/content 而其他所有内容(例如 /api/auth)只会给我以下错误:
XHR POST http://localhost:4200/api/auth
Status
404
Not Found
VersionHTTP/1.1
Transferred424 B (148 B size)
Referrer Policystrict-origin-when-cross-origin
I have created an angular proxy to bypass CORS during development. The problem is, that the proxy seems to only apply to one route and it's not applied to anything else. Is there something aside the proxy config I should be aware of? My backend is located on cloud, separate from my development environment.
Here is the configuration for my proxy:
{
"/api/*": {
"target": "http://x.x.x.x:3000",
"secure": false
}
}
The route that works is /api/content while everything else (such as /api/auth) just gives me the following error:
XHR POST http://localhost:4200/api/auth
Status
404
Not Found
VersionHTTP/1.1
Transferred424 B (148 B size)
Referrer Policystrict-origin-when-cross-origin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我来说是一个愚蠢的错误,由错误说路由“http://localhost:4200/api/auth”是 404 引起的。这让我认为代理不起作用,因为在这种情况下我期望错误为“http://xxxx/auth”为 404。实际上,代理正在工作,但服务器上的 api 尚未创建这样的端点。在我为 /auth 创建 POST api 挂钩后,该错误已修复。
This was kind of a silly mistake on my part caused by the error saying that the route "http://localhost:4200/api/auth" was 404. This made me think that the proxy was not working because in that case i expected the error to be "http://x.x.x.x/auth" being 404. In reality the proxy was working, but the api on the server did not yet have such an end point created to it. The error was fixed after I created the POST api hook for /auth.