728x90
const functions = require('firebase-functions');
// // Create and Deploy Your First Cloud Functions
//
exports.helloWorld = functions.region('asia-northeast3').https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
exports.addMessage = functions.region('asia-northeast3').https.onRequest(async (req, res) => {
// Grab the text parameter.
const original = req.query.text;
// Push the new message into Firestore using the Firebase Admin SDK.
const writeResult = await admin.firestore().collection('messages').add({original: original});
// Send back a message that we've successfully written the message
res.json({result: `Message with ID: ${writeResult.id} added.`});
});
exports.makeUppercase = functions.firestore.document('/messages/{documentId}')
.onCreate((snap, context) => {
// Grab the current value of what was written to Firestore.
const original = snap.data().original;
// Access the parameter `{documentId}` with `context.params`
functions.logger.log('Uppercasing', context.params.documentId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to Firestore.
// Setting an 'uppercase' field in Firestore document returns a Promise.
return snap.ref.set({uppercase}, {merge: true});
});
728x90
'개발 > Firebase' 카테고리의 다른 글
Firebase function(공식 깃허브) (0) | 2022.01.15 |
---|---|
function 중요 팁(unexpected token -> async await) (0) | 2022.01.14 |
Firebase cli reference (0) | 2022.01.02 |
Firebase init 못할 때! deploy firebase function init (0) | 2022.01.02 |
Firebase와 fastlane으로 자동배포하기 (0) | 2022.01.02 |