Skip to content

Instantly share code, notes, and snippets.

@raphox
Created April 6, 2023 14:21
Show Gist options
  • Save raphox/864c9f9330675b2a2deaaad8f0534e06 to your computer and use it in GitHub Desktop.
Save raphox/864c9f9330675b2a2deaaad8f0534e06 to your computer and use it in GitHub Desktop.
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