Skip to content

Instantly share code, notes, and snippets.

@levidurfee levidurfee/index.js Secret
Created May 7, 2019

Embed
What would you like to do?
Firebase Cloud Function for Content Security Policy
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.cspReport = functions.https.onRequest((request, response) => {
const report = JSON.parse(request.body.toString('utf8'));
const writeResult = admin.firestore().collection('reports').add(report);
writeResult.then((ref) => {
return response.json({result: `Message with ID: ${ref.id} added.`});
}).catch((err) => {
return response.json({result: `Failed. ` + err });
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.