Last active
June 4, 2019 20:09
-
-
Save katowulf/3d72fd1421f76ae1b4c8c9474b20f462 to your computer and use it in GitHub Desktop.
Modular Functions layout for Firebase
This file contains 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
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"}; | |
} |
This file contains 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 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'}); | |
} | |
}); | |
} |
This file contains 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
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