Debug Functions locally
start the functions emulator
We run the functions on their own (serve), or along other emulated services.
npm run serve
firebase emulators:start --only functions
firebase emulators:start --import emulator-data --export-on-exit
Callable functions are designed to be called from the client SDK. We can bypass this requirement locally:
invoke callable functions outside the client SDK
functions:shell starts the functions emulator and starts an interactive CLI shell from which we invoke callable functions with a payload.
firebase functions:shell
npm run shell # alternative
We provide the mandatory data property. It holds the payload:
requestArticles({ data: { name: "Lena" } })
We can also invoke them with curl
curl -s -H "Content-Type: application/json" \
-d '{ "data": { } }' \
http://localhost:5001/imagetale/europe-west1/get_images
wire the client to the emulator
We redirect invocations towards the emulated functions, but only on localhost:
if (location.hostname === "localhost") {
// ...
connectFunctionsEmulator(functions, "localhost", 5001)
}
invoke emulated HTTP functions
We invoke HTTP functions with a HTTP request. The URL pattern is specific to the emulator.
http://localhost:5001/imagetale/europe-west1/get_images