Getting the HTTP error 504 (Gateway timeout) with Node.js and Kong API Gateway on EC2 instance

100 views Asked by At

I'm having problems when trying to call the route of my HTTP GET request. The same program works when I try to make the same communication with a VM which hosts Kong API Gateway. Then I tried to host it on AWS EC2 instance but I figured out this problem.

I opened the ports 8000 and 8001 creating inbound rules in my security group and I tried to modify the kong.conf file as well to allow communication from anyone, but I can't solve.

This is the server's code which has to communicate with Kong:

app.use(cors());

app.get("/api/getorders", async(req, res) => {
  try {
    // Chiamata a Kong API Gateway
    await axios.get(URL_GETALL)
    .then((response) => {
      if (response.status === 200) {  //HTTP OK
        const orders = response.data;
      
        // Invia la risposta al frontend React
        res.status(200).json(orders);
      }
      else {
        console.error("Errore nella chiamata a Kong API Gateway");
      }
    });
  } catch (error) {
    console.error('Errore durante la chiamata a Kong API Gateway per richiesta GET:', error.message);
    res.status(500).json({ error: 'Errore interno del server' });
  } 
});

app.listen(port, '0.0.0.0', () => {
  console.log(`Server avviato su http://localhost:${port}\n`);
});

URL_GETALL is a variabile like "http://IP_ADDRESS:PORT/API_ROUTE".

Which could be the problem?

0

There are 0 answers