繁体   English   中英

firebase 如何测试模拟器是否正在运行?

[英]firebase how do I test if emulator is running?

我正在使用以下代码连接到我的存储模拟器:

const firebaseApp = initializeApp(appConfig.firebase)
storage = getStorage(firebaseApp)
connectStorageEmulator(storage, 'localhost', 9199)

这在模拟器运行时工作正常。 当模拟器没有运行时它也能正常工作! 如果它没有运行,我想做其他类似的事情:

if (emulatorIsConnectedAndEmulatorIsRunning) {
  // do something
} else {
  // do something else
}

如何检测模拟器是否正在运行?

TIA

这是一个答案,不一定是最佳答案,我会很感激其他答案。

基本上,我不仅要模拟存储,还要模拟云功能。

我做了一个这样的云功能:

export const ping = functions.https.onRequest((req, res) => {
  res.json({ ping: 'pong' })
})

所以在我的代码中,我只是 ping 这个端点。 例如:

axios.get(`http://localhost:5001/${storageBucket}/us-central1/ping`)

如果它响应 200,则函数仿真器正在运行(根据我的设置,这也意味着存储仿真器正在运行)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM