问题
Been trying every approach I can think of for hours.
Basically I'm running an AWS Lambda function which does some work to my Firebase app in both a client and server role.
Being on Lambda, I need to be able to reverse the firebase.initializeApp(config)
and firebase.initializeApp(config, 'server')
. I've tried firebase.app('server').delete()
but that doesn't seem to work.
Thanks in advance for any help.
To clarify, I can't just use the existing connection because the config may change.
回答1:
Calls to initializeApp
take an optional app name. If the app name is not specified, the name [DEFAULT]
is used.
To uninitialize an app, you need to call delete
on the app instance. The app instance is returned by the initializeApp
call or can be obtained using the app
function.
That is, you can initialize and uninitialize an app like this:
app = firebase.initializeApp(configuration);
app.delete();
Or like this:
firebase.initializeApp(configuration);
firebase.app('[DEFAULT]').delete();
Note that the delete
function returns a promise that resolves when the app deletion is complete.
回答2:
Alternatively, you can also just initialise the Firebase instance outside of your handler function and pass it down. This prevents it from getting invoked multiple times.
Lambda likes to spin up one instance of a function, but continuously call its function handler, meaning code outside the handler is only executed once.
This can be applied to most anything that only lets you have one instance going.
回答3:
initializeApp
returns the initialized app.
You can do :
const app = firebase.initializeApp(config);
//...
await app.delete();
来源:https://stackoverflow.com/questions/39436072/cannot-destroy-firebase-connections-making-hot-lambda-fail-due-to-firebase-app