简体   繁体   中英

A deployment problem of Firebase cloud functions

I've created my Firebase cloud functions as follows:

index.js: -----------------------------------

const _test1 = require('./testfunc');
exports.test1 = _test1.test1;

const _test2 = require('./testfunc');
exports.test2 = _test2.test2;

testfunc.js: -----------------------------------

const functions = require('firebase-functions');
const common = require('./testCommon');

exports.test1 = functions.https.onRequest((req, res) => {
    res.send(common.coreWork());
});

exports.test2 = functions.https.onRequest((req, res) => {
    res.send(common.coreWork());
});

testCommon.js -----------------------

exports.coreWork = function () {
    return 'My name is John';
}

Then I deployed the functions:

firebase deploy --only functions: test1
firebase deploy --only functions: test2

First test result:

Result of test1 => 'My name is John'
Result of test2 => 'My name is John'

Then I made a modification (John -> Peter) in the common function:

exports.coreWork = function () {
    return 'My name is Peter';
}

Then, I just deployed function test1 again.

firebase deploy --only functions: test1

Second test result:

Result of test1 => 'My name is Peter'
Result of test2 => 'My name is John'  ('Peter' was expected, but in fact it is still 'John')

The problem:

My original thought is that since the common function will be updated when function test1 is updated, function test2 should be following the update implicitly as well. But in fact, it doesn't work. If I want function test2 to be updated, I have to explicitly do the deployment (for test2) again.

So if I want the functions to be updated the way I originally expected, what should I do? Thanks.

The behavior you're observe is working as expected. Each function deployment is completely isolated from each other - each one has its own copy of the code. Deploying a function will never alter the way another function works.

If you want test2 to behave differently after modifying your code, you will have to deploy it again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM