Skip to content

Instantly share code, notes, and snippets.

@katowulf
Last active June 4, 2019 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katowulf/3d72fd1421f76ae1b4c8c9474b20f462 to your computer and use it in GitHub Desktop.
Save katowulf/3d72fd1421f76ae1b4c8c9474b20f462 to your computer and use it in GitHub Desktop.
Modular Functions layout for Firebase
export const run = (data, context) => {
const path = data.path;
if( path !== "bar" ) {
throw new functions.https.HttpsError('invalid-argument', "Path was not valid");
}
return {foo: "bar"};
}
const cors = require('cors')({
origin: true,
});
export const run = (req, res) => {
const path = req.query.path;
return cors(req, res, () => {
if( path === "foo" ) {
res.send({foo: "bar"}),
}
else {
res.status(400).send({error: 'Invalid path'});
}
});
}
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
export const callableFunction = functions.https.onCall(require('./call').run);
export const getViaRest = functions.https.onRequest(require('./get').run);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment