Skip to content

Instantly share code, notes, and snippets.

@Charpell
Last active November 9, 2018 16:36
Show Gist options
  • Save Charpell/2323d4c6cb07ee2f30c922c7863561a3 to your computer and use it in GitHub Desktop.
Save Charpell/2323d4c6cb07ee2f30c922c7863561a3 to your computer and use it in GitHub Desktop.
exports.addItem = functions.https.onRequest((req, res) => {
return cors(req, res, () => {
if(req.method !== 'POST') {
return res.status(401).json({
message: 'Not allowed'
})
}
console.log(req.body)
const item = req.body.item
database.push({ item });
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(error.code).json({
message: `Something went wrong. ${error.message}`
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment