Skip to content

Instantly share code, notes, and snippets.

@Charpell
Created May 16, 2018 08:51
Show Gist options
  • Save Charpell/5fbc3138f3266fda9f1228168ccd21d8 to your computer and use it in GitHub Desktop.
Save Charpell/5fbc3138f3266fda9f1228168ccd21d8 to your computer and use it in GitHub Desktop.
exports.getItems
exports.getItems = functions.https.onRequest((req, res) => {
return cors(req, res, () => {
if(req.method !== 'GET') {
return res.status(500).json({
message: 'Not allowed'
})
}
let items = [];
return database.on('value', (snapshot) => {
snapshot.forEach((item) => {
items.push({
id: item.key,
items: item.val().item
});
});
res.status(200).json(items)
}, (error) => {
res.status(500).json({
message: `Something went wrong. ${error}`
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment