I need await request in app.post and use request outside function. I wrote some code, it works, but sometimes it freezes
receivePost(url, response) {
const app = this.app;
return new Promise( (resolve, reject) => {
app.post(url, async (req, res) => {
res.send(response)
try {
resolve(req.body);
} catch {
reject();
}
req.end();
});
});
}
The problem arises when I am trying get request twice and more. I try restart Server with function this.app.listen and this.server.destroy between usage.