One of my routes always logs this "Cannot remove headers after they are sent" error. Everything functions correctly and the 200 response and sent string are all successful. My route looks like this:
app.get('/category/:service', auth, async (req, res, next) => {
//conditionally use middleware https://stackoverflow.com/a/21293587/2293288
if (req.params.service == 'service1') {
await service1(req, res, next);
}
if (req.params.service == 'service2') {
await service2(req, res, next);
}
res.status(200).send('Thank you');
});
and service2:
export const service2 = async (req, res, next) => {
try {
//googleapi data added to db
const example = await googleapi.create();
next();
return;
} catch (err) {
console.error('Error:', err);
res.status(403).send('Error');
return;
}
};
This is the first time I have tried to structure a route like this, so I expect I messed something up within the if statements...