I have a promise chain in my function and want to enable cors, but to do so I need to wrap my function like that:
module.exports = (req, res) => {
cors(req, res, () => {
return thisReturnsPromise()
.then((errands) => {
res.status(200).send('OK')
})
.catch((error) => {
res.status(500).send(`Error.`);
});
});
};
https://www.npmjs.com/package/cors
The problem is that cors doesn't care if the callback returns promise, so my function cannot wait for my promises and also testing is impossible.
How can I have cors and promises at the same time?