Firebase Emulator Suite
Firebase.jl can talk to the local Firebase Emulator Suite instead of live Firebase, which is handy for tests and local development.
using Firebase
# Use the standard *_EMULATOR_HOST environment variables, if set
use_emulator()
# Or name services explicitly (true = default port on localhost)
use_emulator(firestore=true, database=true, auth=true, storage=true,
project_id="demo-firebase")
# Switch every service back to live Firebase
use_production()When a service is emulated, requests to it use the emulator's owner token, so no service-account credentials are needed. Services that are not emulated keep using live Firebase and your real credentials.
| Service | Environment variable | Default port |
|---|---|---|
| Firestore | FIRESTORE_EMULATOR_HOST | 8080 |
| Realtime DB | FIREBASE_DATABASE_EMULATOR_HOST | 9000 |
| Auth | FIREBASE_AUTH_EMULATOR_HOST | 9099 |
| Storage | FIREBASE_STORAGE_EMULATOR_HOST | 9199 |
Firebase.auth_url — Method
auth_url() -> StringBase URL for Firebase Auth (Identity Toolkit) REST calls.
Firebase.database_ns — Method
database_ns() -> StringRealtime Database namespace used for the ?ns= query parameter in emulator mode.
Firebase.emulator_active — Method
emulator_active(service::Symbol) -> BoolReturn true when service (:firestore, :database, :auth, or :storage) is currently pointed at an emulator.
Firebase.emulator_running — Method
emulator_running(hostport::AbstractString) -> BoolBest-effort check that something is listening on hostport ("host:port"), used to gate integration tests. Returns false if the connection cannot be established.
Firebase.firestore_url — Method
firestore_url() -> StringBase URL for Firestore REST calls: the emulator host when active, otherwise live.
Firebase.use_emulator — Method
use_emulator(; host="localhost", firestore=nothing, database=nothing,
auth=nothing, storage=nothing, project_id="demo-firebase",
detect_env=true)Point the package at the local Firebase Emulator Suite.
For each service you may pass an explicit "host:port" string, true to use the standard port on host, or leave it nothing. When detect_env is true, the standard *_EMULATOR_HOST environment variables are read for any service not given explicitly. If nothing is specified for a service and no env var is set, that service stays live.
Calling use_emulator() with no arguments enables every service whose env var is set, falling back to the default ports on host only for services you request.
Example
use_emulator() # from FIRESTORE_EMULATOR_HOST etc.
use_emulator(firestore=true, database=true) # localhost:8080 / localhost:9000
use_emulator(firestore="127.0.0.1:8080", project_id="my-demo")Firebase.use_production — Method
use_production()Clear all emulator configuration and route every service back to live Firebase.