Since I upgraded Cloud Functions for Firebase to Node8 and ES17 a TsLint error shows up when trying to update a function. It throws Promises must be handled appropriately
for this chunk of code:
app.get('*', (req, res) => {
const isBot = detectBot(req.headers['user-agent']);
if (isBot) {
const botUrl = generateUrl(req);
// If bot, fetch url via rendertron
fetch(`https://foo.com/render/${botUrl}`)
.then(rendertronRes => rendertronRes.text())
.then(body => {
res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
res.set('Vary', 'User-Agent');
res.send(body.toString());
});
} else {
// Not a bot, fetch the regular Angular app
fetch('https://bar.com/')
.then(regularRes => regularRes.text())
.then(body => {
res.send(body.toString());
})
.catch(err => res.send(err));
}
});
The strangest part is that it complains about the second fetch, but not the first.