0

After many attempts to solve the issue, I turn for your help friends.

I cannot access the simple "hello world" fastify app running on a Google Cloud virtual machine. The app is listening on port 3000. When I perform a GET request at http://34.165.64.213:3000/ - I receive the following error:

GET http://34.165.64.213:3000/
Error: connect ECONNREFUSED 34.165.64.213:3000

app code:

const fastify = require('fastify')({
 logger: true
})

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

const start = async () => {
 try {
   await fastify.listen({ port: 3000 })
 } catch (err) {
   fastify.log.error(err)
   process.exit(1)
 }
}
start()

firewall settings:

{
  "allowed": [
    {
      "IPProtocol": "tcp",
      "ports": [
        "3000"
      ]
    }
  ],
  "creationTimestamp": "2023-07-08T01:09:47.176-07:00",
  "description": "",
  "direction": "INGRESS",
  "disabled": false,
  "enableLogging": true,
  "id": "5695192685623944996",
  "kind": "compute#firewall",
  "logConfig": {
    "metadata": "INCLUDE_ALL_METADATA",
    "enable": true
  },
  "name": "allow-http-3000",
  "network": "projects/videocode/global/networks/default",
  "priority": 1000,
  "selfLink": "projects/videocode/global/firewalls/allow-http-3000",
  "sourceRanges": [
    "0.0.0.0/0"
  ],
  "targetTags": [
    "allow-http-3000"
  ]
}

When I try to run the express app on the same virtual machine instance and on the same port (3000) - it works well.

Is it something special about fastify or a general connectivity issue?

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
Toto
  • 13
  • 3

1 Answers1

0

it seems that by default fastify apps are set to be accessed via the localhost. So I had to change the fastify server settings in index.js so that it is open for all IPs:

await fastify.listen({
  port: 3000,
  host: '0.0.0.0'
})
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Toto
  • 13
  • 3