[英]Axios throwing connection error even though postman is working for same endpoint
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const { APP_PORT } = require("./config/index");
const { CustomError, CustomErrorWithHeader, handleError } = require("./helpers/error");
const routes = require("./routes");
const app = express();
const axios = require("axios");
app.set("views", "src/views");
app.set("view-engine", "ejs");
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.disable("x-powered-by");
app.use(express.static("src/public"));
app.get("/axioshit", async(req, res) => {
const response = await axios.get("http://localhost:4120/api/um/user/password-settings");
res.send(response);
});
app.use(routes);
app.use((err, req, res, next) => {
console.log("ERROR GENERATED", err);
if (err instanceof CustomError) handleError(err, res);
else if (err instanceof CustomErrorWithHeader) handleError(err, res);
else {
// console.log(err);
res.status(500).json({
success: false,
message: "Internal server error",
statusCode: 500
});
}
});
app.listen(APP_PORT, (err) => {
if (err) console.log(err);
console.log(`Server Running On Port:${APP_PORT}`);
});
(node:267) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:4120 sc-um-ui |
(节点:267)UnhandledPromiseRejectionWarning:错误:连接 ECONNREFUSED 127.0.0.1:4120 sc-um-ui | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1134:16)
在 TCPConnectWrap.afterConnect [as oncomplete] (net.js:1134:16)
I have shared the endpoint and Error.To be frank I also donot have much to go on.When I am trying to hit same endpoint with postman its working just fine.Yet Axios is throwing error.I have searched net for quite a bit yet could not find any actual answers.Most of cases people said it got resolved by itself which I am skeptical about.Can anyone help?Oh and the App is running inside a docker container我已经共享了端点和错误。坦率地说,我对 go 也没有太多了解。当我试图用 postman 到达相同的端点时,它工作得很好。然而 ZD3E28535C74CCEE29182AEB3CF837E9 正在搜索一个相当小的错误。找不到任何实际答案。大多数情况下人们说它自己解决了,我对此表示怀疑。有人可以帮忙吗?哦,应用程序在 docker 容器内运行
The backend code was okay.Problem was that I wasn't exposing the docker container network externally.Hence it refused to connect to a network outside Docker container.Basically the problem was created because of docker config.后端代码没问题。问题是我没有在外部公开 docker 容器网络。因此它拒绝连接到 Docker 容器之外的网络。基本上问题是由于 Z05B6053C41A2134E6ZB6 配置造成的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.