I am connecting to my storage emulator with the following code:
const firebaseApp = initializeApp(appConfig.firebase)
storage = getStorage(firebaseApp)
connectStorageEmulator(storage, 'localhost', 9199)
This works fine when the emulator is running. It also works fine when the emulator is NOT running! if its not running I want to do something else like this:
if (emulatorIsConnectedAndEmulatorIsRunning) {
// do something
} else {
// do something else
}
How can I detect whether the emulator is running or not?
TIA
This is AN answer, not necessarily the best answer and I would appreciate other answers.
Basically, I am not just emulating storage but also cloud functions.
I've made a cloud function like this:
export const ping = functions.https.onRequest((req, res) => {
res.json({ ping: 'pong' })
})
So in my code I just ping this endpoint. For example:
axios.get(`http://localhost:5001/${storageBucket}/us-central1/ping`)
If it responds 200 then the function emulator is running (and given my setup this also means the storage emulator is running).