我正在尝试创建一些Firebase Cloud功能并使用]在本地对其进行测试>
firebase emulators:start --only functions
这些功能应该使用提取来调用某些外部服务。
[我发现将功能部署到Firebase云时可以调用这些外部服务,但是在模拟器中本地运行时不能调用它们:
import 'cross-fetch/polyfill'; export const fetchTest = functions .region(config.firebaseRegion) .https.onRequest((request: Request, response: Response) => { fetch("https://www.wikipedia.org/", { method: 'GET', }).then(value => { console.log("Fetched: ", value); }).catch(reason => { console.log("Fetch failed: ", reason); }); fetch("https://googleapis.com/foo", { method: 'GET', }).then(value => { console.log("Fetched: ", value); }).catch(reason => { console.log("Fetch failed: ", reason); }); response.send("Done"); });
这是在模拟器中调用fetchTest时得到的输出:
⚠ Unknown network resource requested! - URL: "https://www.wikipedia.org/" ⚠ Google API requested! - URL: "https://googleapis.com/foo" - Be careful, this may be a production service.
查看源代码,似乎在模拟器中实现了一些过滤:
if (href && !history[href]) { history[href] = true; if (href.indexOf("googleapis.com") !== -1) { new EmulatorLog("SYSTEM", "googleapis-network-access", "", { href, module: bundle.name, }).log(); } else { new EmulatorLog("SYSTEM", "unidentified-network-access", "", { href, module: bundle.name, }).log(); } }
是否有任何此类限制的原因?对此有解决方法吗?
谢谢!
我正在尝试创建一些Firebase Cloud函数并使用firebase模拟器在本地对其进行测试:start --only函数这些函数应该使用fetch调用某些外部服务。我发现...
当您看到“请求未知网络”这样的日志时: