Created
April 6, 2023 14:21
-
-
Save raphox/864c9f9330675b2a2deaaad8f0534e06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require("firebase-functions"); | |
require("dotenv").config(); | |
exports.answerQuestion = functions.firestore | |
.document("/questions/{questionId}") | |
.onCreate((snap, context) => { | |
const data = snap.data(); | |
functions.logger.log( | |
"Answering question", | |
context.params.questionId, | |
data.title, | |
); | |
fetch(process.env.RENDER_API_URL, { | |
method: "post", | |
body: JSON.stringify({ | |
data, | |
collection: "questions", | |
document: context.params.questionId, | |
}), | |
headers: { | |
"Content-Type": "application/json", | |
"Authorization": `Bearer ${process.env.SECURITY_TOKEN}`, | |
}, | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment