我想在本地运行一个 firebase http 云函数来访问一个真正的远程 Firestore 数据库。
为此,我使用以下方法在本地运行我的函数:
FIREBASE_CONFIG="/path-to-credential.json" GOOGLE_APPLICATION_CREDENTIALS="/path-to-credential.json" firebase emulators:start --only functions
如此处https://firebase.google.com/docs/admin/setup所写,这应该允许在没有任何参数的情况下初始化 admin sdk。我的功能index.js如下
import * as admin from 'firebase-admin';
import * as fromHttpFunc from './http/func';
admin.initializeApp();
export const httpFunc = fromHttpFunc.httpFunc;
Run Code Online (Sandbox Code Playgroud)
当我然后在浏览器中调用该函数时,这就是我在日志中得到的
[warn] ? The Cloud Firestore emulator is not running so database operations will fail with a 'default credentials' error.
[debug] [2019-07-20T13:16:28.656Z] [runtime-status] Ephemeral server survived. {}
[info] > (node:41939) UnhandledPromiseRejectionWarning: Error: The incoming JSON object does not contain a client_email field …Run Code Online (Sandbox Code Playgroud) node.js firebase-tools google-cloud-functions google-cloud-firestore