简体   繁体   English

即使 postman 正在为同一端点工作,Axios 也会引发连接错误

[英]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.

相关问题 React js axios在邮递员中工作时出现CORS错误 - CORS ERROR in React js axios when its working in postman 端点或路由不准确? (axios 调用在代码中有效,但在邮递员上无效) - Endpoint or route inaccurate? (axios call works in code but not on postman) 为什么即使在 postman 中测试了请求,Axios 也会超时? - Why Axios is timing out even when the request is tested in postman? 为什么即使在邮递员中可以看到标头也为什么会出现Access-Control-Allow-Origin标头错误 - Why I get Access-Control-Allow-Origin header error even though I can see the header in postman 尽管给出了字段输入,但 Postman 上的验证错误 - Validation error on Postman though field inputs are given 为什么我在模式静态方法上定义的错误消息没有显示,即使错误处理显然有效? - Why are my error messages defined on a schema static method not showing up even though the error handling is apparently working? 我的一条路线的参考错误,即使它与其他路线完全相同 - Reference Error with one of my routes, even though it's the exact same as the others 抛出错误无法在邮递员中发布 /api/password-reset - Throwing error Cannot POST /api/password-reset in postman 在 PRN 应用程序中,PUT 请求无法在 Web 应用程序上通过,即使它在 Postman 中也是如此 - in PERN App, PUT request does not get through on a Webapp, even though it does in Postman Postman 返回 HTML 即使我的 API 路线正确,它也显示无法发布 - Postman Returns HTML which shows can not Post even though my API route is correct
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM