【发布时间】:2021-03-17 12:53:49
【问题描述】:
我正在使用 Firebase 模拟器来测试我的云功能。我要执行的代码是:
import * as functions from "firebase-functions";
const fetch = require('node-fetch');
export const newZipCode = functions.database.ref('/zipCodes/{zipCode}').onCreate(async (snapshot, context) => {
const api = await fetch(`https://api.papapi.se/lite/?query=${context.params.zipCode}&format=json&apikey=xxx`);
const json = await api.json();
console.log(context.params.zipCode);
if (api.ok) {
snapshot.ref.update({
latitude: json.results[0].latitude,
longitude: json.results[0].longitude
});
} else {
console.log(${api.status}));
}
});
但是,当我尝试运行 Firestore 和 Functions 模拟器时,我收到以下错误消息:
"缺少预期的 firebase 配置值 databaseURL,config 实际上是{"storageBucket":"xxxx-yyyy.appspot.com","projectId":"xxxx-yyyy"}"
Cloud Functions 和 Firestore 仿真器不应该能够直接进行通信吗?如果没有,需要做什么才能让模拟器运行?仅供参考,我正在运行 Node.js 14 和 Firebase 版本 9.6.1。
【问题讨论】:
-
如何启动模拟器?
-
@fjc "firebase emulators:start --only functions,firestore" 或者只是 "firebase emulators:start"
标签: javascript firebase google-cloud-firestore google-cloud-functions firebase-tools