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:
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.