Express-http-proxy agent api but request Times wrong connect ECONNREFUSED

use express-http-proxy to delegate all api requests from the front end to another service, but the front end issues an api request. Time error connect ECONNREFUSED: 127.0.0.1 api 6667

at first I thought that the port was occupied or the mongodb service was not open, but it was no problem to connect to the database

node Code

const app = new Express();
const targetUrl = "127.0.0.1:6667";

const proxy = httpProxy.createProxyServer({
    target:targetUrl
})


app.use("/api",(req,res)=>{
    proxy.web(req,res,{target:targetUrl})
});

frontend request code

router.get("/getAllTags", function (req, res) {
    Tags.find(null, "name").then(data => {
        responseClient(res, 200, 0, "", data);
    }).catch(err => {
        responseClient(res);
    })
});

Database connection and listening api path

//
app.use("/", require("./main"));
//
app.use("/admin", require("./admin"));

mongoose.Promise = require("bluebird");
mongoose.connect(`mongodb://${config.dbHost}:${config.dbPort}/blog`, function (err) {
    if (err) {
        console.log(err, "");
        return;
    }
    console.log("");

    app.listen(port, function (err) {
        if (err) {
            console.error("err:", err);
        } else {
            console.info(`===> api server is running at ${config.apiHost}:${config.apiPort}`)
        }
    });
});

when node"s newcomer was developing a personal blog, the api agent made a mistake and bothered to ask for help all morning

Mar.11,2022
Menu