Debug Functions locally
start the functions emulator
We run the functions with other emulators, or on their own:
firebase emulators:start
firebase emulators:start --import emulator-data --export-on-exit
firebase emulators:start --only functions
npm run serve
invoke callable functions through the SDK
We redirect client invocations towards the emulated functions, but only on localhost:
if (location.hostname === "localhost") {
// ...
connectFunctionsEmulator(functions, "localhost", 5001)
}
invoke callable functions outside the client SDK
We can invoke callable functions outside the client SDK as long as the function emulator is running.
The emulator exposes them on specific URLs. We get the URLs when starting the emulators:
http://localhost:5001/imagetale/europe-west1/get_images
Callable functions can be invoked:
- directly, with a local HTTP request
- through the Firebase REPL shell.
In both cases, the request's data must be present in the data key of the request's body (JSON). The data key must exist.
Note: We turn off authentication requirements when calling callables outside the client SDK
calling functions with curl
We can invoke callable functions with curl:
curl -H "Content-Type: application/json" \
-d '{ "data": { } }' \
http://localhost:5001/imagetale/europe-west1/get_images
calling functions with the Firebase REPL
functions:shell starts the functions emulator and an interactive CLI shell from which we invoke callable functions.
firebase functions:shell
We provide the data key and its content, which represents the request's data:
generateExample({ data: { word: "你好" } })