项目作者: cerebral

项目描述 :
Work locally with firebase functions
高级语言: JavaScript
项目地址: git://github.com/cerebral/firebase-functions-mock.git
创建时间: 2017-06-20T08:15:46Z
项目社区:https://github.com/cerebral/firebase-functions-mock

开源协议:MIT License

下载


firebase-functions-mock

Work locally with firebase functions

Install

npm install firebase-functions-mock

Supports

  • onRequest express app handling
  • onWrite database event handling
  • Mocks out auth and config
  • Runs static delivery of your public files folder

How to use

functions/index.js

  1. const firebase = require('firebase-admin');
  2. const admin = firebase.initializeApp({
  3. credential: firebase.credential.cert(JSON.parse(process.env.SERVICE_ACCOUNT)),
  4. databaseURL: JSON.parse(process.env.FIREBASE_CONFIG).databaseURL,
  5. });
  6. let functions = require('firebase-functions');
  7. // When in debug mode, override functions with the mock and
  8. // pass in the instance of "admin" and optional options
  9. if (process.env.NODE_ENV !== 'production') {
  10. functions = require('firebase-functions-mock')(admin, {
  11. config: process.env.FIREBASE_CONFIG,
  12. port: 3001,
  13. publicPath: 'public'
  14. });
  15. }
  16. exports.app = functions.https.onRequest(require('./app'));
  17. exports.publish = functions.database.ref('articles/{uid}/{articleName}').onWrite(require('./publish'));

Limitations

This project is in its initial state to build the jsblog.io project. It has a lot of potential for improvements. Although contributions are already made, here are some things to look into:

  • Test more scenarios with onWrite usage

Get going

To get going with Firebase Functions I highly recommend using this boilerplate which has the whole workflow set up for you.