I have a React frontend that uses axios within a generator. I've added timeout of 0 in both the instance and the request itself just to be sure as I've read that 0 means there's no timing out. I also tried a 600000 timeout value.
// REACT / REDUX SAGA
axios.defaults.timeout = 0;
const response = yield axios.post('/iteminfo/', {
data
}, { timeout: 0 });
const itemInfo = response.data;
On my nginx / node server with express I have it requesting from another server, data that takes a long time to gather. It takes 1 minute and 20 seconds approximately. I added 10 minutes of timeout to the node app to try to address this.
// NODE / EXPRESS SERVER
app.timeout = 1000 * 60 * 10; // 10 minutes
app.listen(port, () => {
console.log(`${portalStatus} NodeJS Listening on port ${port}`)
});
// SERVER TO SERVER REQUEST
axios.defaults.timeout = 1000 * 60 * 10; // 10 minutes
axios.post(baseURL2 + 'itemgather_api.php', qs.stringify(req.body))
.then(function (response) {
console.log('Successfully gathered item...', response.data);
res.json(response.data);
})
.catch(function (error) {
handleError(error);
res.status(400).json({error:error});
});
Looking at the backend PM2 logs I can confirm that the axios request from my server requesting the long data from another server had been resolved. But when it comes to pushing that data back as a response for my frontend there's something that goes wrong.
My frontend's axios POST request leads to this error after only 1 minute :
Error: Request failed with status code 504
at e.exports (2.9443c470.chunk.js:1)
at e.exports (2.9443c470.chunk.js:1)
at XMLHttpRequest.d.onreadystatechange (2.9443c470.chunk.js:1)
My thinking is that it is the frontend that's timing out, not the backend, and it closes the connection after 1 minute, can anyone help me address this please?
I already set both frontend and backend's timeout to be longer based on some stackoverflow answers so I can't figure out what else I'm missing.