简体   繁体   中英

Why nodejs http request doesn't work when accessing a local served express app?

I have an express REST API app running on 8082. Then I'm trying to do a call from my another app using request:

request.post({
    url: 'http://localhost:8082/test',
    method: 'POST',
    json: {
        code: 'Hello'
    }   
}, (err, res, body) => {
    console.log(err)
    console.log(res)
    console.log(body)
})

But I'm getting a 502 Bad Gateway error:

<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.10.1</center>
</body>
</html>

Does it look like it's looking into Nginx but not to expressjs?

How can I force it to look into my running app?

检查其他应用程序代码中的正确端口,或者如果nginx正在侦听该端口,则更改该端口。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM