This is Javascript
const fetch = require("node-fetch").default;
let iApi = express.Router();
iApi.post("/update/:name/:value", async (req, res) => {
const name = req.params["name"];
const value = req.params["value"];
const headers = { ...req.headers };
const url = `${process.env.URL}/name/${name}/value/${value}`;
const options = {
url: url,
method: "post",
headers: headers,
gzip: true,
};
//if (process.env.NODE_ENV === "development") {
// options.agent = agent;
//}
// request(options, function(err, response, body) {
// handleResponseNoBody(err, response, body, res, url)
// })
const response = await fetch(url, options);
if (response.status == 200) {
logger.info({
...LOG_DEFAULTS,
endpoint: url,
methodName: "update",
description:
"update",
c_id: req.cId,
res,
req,
});
const data = await response.json();
res.send(data);
} else {
res.status(response.status).send(JSON.parse(data));
}
});
I changed commented lines which used request library and did not have async/await to node-fetch with async and await but now I am getting 504 Gateway Timeout error and I am not sure why, this does not happen with request package though, any help is much appreciated.