Vue로 PWA 개발 - 그랜파 개발자
마이로그를 저장하면 구독자에게 알림을 전송하는 기능을 구현합니다. 잎에서 구현한 FCM 푸시 메시지 전송 기능을 그대로 두고 새로운 함수로 기능을 구현하고자 합니다.
Firebase Cloud Functions에서 여러 함수를 export해야 합니다.
To export multiple functions from Firebase Cloud Functions, you can define each function separately and then export them all within the same exports object. Firebase Functions uses the exports object to expose the functions, and you can include as many functions as you need in a single Firebase project.
Firebase Cloud Functions에서 여러 함수를 내보내려면 각 함수를 별도로 정의한 다음 동일한 '내보내기' 개체 내에서 모두 내보낼 수 있습니다. Firebase Functions는 'exports' 개체를 사용하여 함수를 노출하며 단일 Firebase 프로젝트에 필요한 만큼 많은 함수를 포함할 수 있습니다.
Let’s assume you want to define two HTTP functions and one Firestore-triggered function in your Firebase project.
Firebase 프로젝트에서 HTTP 함수 2개와 Firestore에서 트리거되는 함수 1개를 정의한다고 가정해 보겠습니다.
const { onRequest } = require('firebase-functions/v2/https');
const { onDocumentCreated } = require('firebase-functions/v2/firestore');
const admin = require('firebase-admin');
// Initialize Firebase Admin SDK
admin.initializeApp();
// First HTTP function (onRequest) to send a notification
exports.sendNotification = onRequest((req, res) => {
res.send('Notification sent!');
});
// Second HTTP function (onRequest) to greet the user
exports.greetUser = onRequest((req, res) => {
const name = req.query.name || 'Guest';
res.send(`Hello, ${name}!`);
});
// Firestore-triggered function (onDocumentCreated) to log new documents
exports.logNewDocument = onDocumentCreated('/users/{userId}', (event) => {
const newValue = event.data;
console.log('New user created:', newValue);
});
logNewDocument: Logs information about a new document added to the /users/{userId} Firestore collection.
logNewDocument: /users/{userId} Firestore 컬렉션에 추가된 새 문서에 대한 정보를 기록합니다.
To deploy these multiple functions, run the following Firebase CLI command:
이러한 여러 함수를 배포하려면 다음 Firebase CLI 명령어를 실행하세요.
firebase deploy --only functions
Firebase will deploy all functions defined in the exports object.
Firebase는 exports 객체에 정의된 모든 함수를 배포합니다.
This approach allows you to manage and export multiple Firebase Functions in a single project effectively.
이 접근 방식을 사용하면 단일 프로젝트에서 여러 Firebase 함수를 효과적으로 관리하고 내보낼 수 있습니다.