I am currently working with Firebase and Firebase functions. I am trying to get documents within a collection (collection : 'items'). I tried doing a GET, however I only get a 200 and empty body.
app.get('/api/read/items', (req, res) => {
(async () => {
try {
let response = [];
let itemRefs = db.collection('items').get().then(snapshot => {
snapshot.forEach((item) => {
response.push(item.data());
});
console.log(response);
});
return res.send(response);
} catch (error) {
debug.log(error);
return res.status(500).send(error);
}
})();
});

Interestingly when I query a specific item, I get the JSON body with the document data included:
app.get('/api/read/:item_id', (req, res) => {
(async () => {
try {
const document = db.collection('items').doc(req.params.item_id);
let item = await document.get();
let response = item.data();
return res.status(200).send(response);
} catch (error) {
console.log(error);
return res.status(500).send(error);
}
})();
});
Looking forward to see what mistake I made :)!
Thank you for your help!