错误反应代理错误:无法代理请求
为什么我会收到此错误:
代理错误:无法将请求 /api/v1/management/me 从 localhost:3000 代理到 http://localhost:8080 (ECONNREFUSED)。
得到了这个 axios 设置:
axios.defaults.baseURL = "http://localhost:3000/";
并在 package.json
中设置它:
"proxy": "http://localhost:8080"
也尝试过:
"proxy": "http://localhost:8080/"
并进行以下调用:
axios({
method: "get",
url: "api/v1/management/me",
data: {},
headers: { crossDomain: true },
})
当我直接调用http://localhost:8080/api/v1/management/me
我收到了服务器的响应。
我有以下后端,蒸气路线设置。也许这里有问题/具体?
let protectedAPIRouter = authSessionRouter.grouped("api/v1").grouped(User.guardAuthMiddleware())
let managementAPIRouter = protectedAPIRouter.grouped("management")
Why do I got this error:
Proxy error: Could not proxy request /api/v1/management/me from localhost:3000 to http://localhost:8080 (ECONNREFUSED).
Got this axios setting:
axios.defaults.baseURL = "http://localhost:3000/";
And set this in package.json
:
"proxy": "http://localhost:8080"
tried also:
"proxy": "http://localhost:8080/"
And have following call:
axios({
method: "get",
url: "api/v1/management/me",
data: {},
headers: { crossDomain: true },
})
When I call directly http://localhost:8080/api/v1/management/me
I got response from server.
I have following backend, Vapor route setting. Maybe something wrong / specific here?
let protectedAPIRouter = authSessionRouter.grouped("api/v1").grouped(User.guardAuthMiddleware())
let managementAPIRouter = protectedAPIRouter.grouped("management")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议采用以下解决方案:
localhost
更改为 IP 地址:"proxy": "http://your_IP_address:8080"
I would suggest the following solutions:
localhost
to IP address:"proxy": "http://your_IP_address:8080"
我解决了这个问题,通过客户端项目将 package.json 中的 localhost 更改为 127.0.0.1。
I solved this issue change localhost to 127.0.0.1 in the package.json over the client project.
您需要为您想要访问的后端服务设置代理。
You need to set up a proxy to the backend service you want to access.