Hi I have created one cloud function getUsers
. Its can be accessed like https://xyz.cloudfunctions.net/getUsers
exports.getUsers = functions.https.onRequest((request, response) => {
});
I need to do some changes in the function and want to keep same function name. I want to add version in the cloud function so that it can be accessed like this
https://xyz.cloudfunctions.net/getUsers/v2
What is the way to do this in cloud function for Firebase ?
Run firebase tools --version to check version. And as per the prompt, run npm install -g firebase-tools to update.
You can choose to run all functions in a project exclusively on the runtime environment corresponding to one of these supported Node. js versions: Node. js 16.
There is no built-in versioning for Cloud Functions. The closest you can get on the default URLs is writing the version into the function name: getUsers_v2
.
If you're using Firebase Hosting to give friendly URLs to your Cloud Functions, you can of course map each individual function to the URL you want.
One way of doing is this to make your own path handler. Of course, you can use express but I chose not to use it just for this.
exports.getUsers = functions.https.onRequest((request, response) => {
const path = request.path; // '/getUsers/v2'
const version = path.split('/')[2]; // ['', 'getUsers', 'v2']
switch ( version ) {
case 'v1': // Handle for v1;
break;
case 'v2': // Handle for v2;
break;
}
});
This will expose your endpoint till https://xyz.cloudfunctions.net/getUsers
but for trailing versions or any other stuff in url, you can use a handler like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With