简体   繁体   中英

nodejs 5500 port API get connect refused

Using fastify to build some nodejs backend API, here is part of my code snippet:

fastify.get('/', async (request, reply) => {
        return { data: 'ok...' }
})

Deploy it on my Tencent Clound Server

Install some related dependencies, and using pm2 to keep my application online. Using curl to test my API currectly:

curl http://localhost:5500/

{"data":"ok..."}

But when I tried to request my test api using public ip address: http://1.xx.xx.xx:5500/ , but it reminded me: connect refused.

And I tried to use curl to test my API by 127.0.0.1, get the same error:

curl http://127.0.0.1:5500/
//  connect refused

PS:

I have disabled firewall: 在此处输入图像描述

And the 5050 port is open on my cloud server:

在此处输入图像描述

You should set listen at address 0.0.0.0

fastify.listen(5500, '0.0.0.0', function (err, address) {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
  fastify.log.info(`server listening on ${address}`)
})

Link at Note

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