简体   繁体   English

Firebase云功能部署问题

[英]A deployment problem of Firebase cloud functions

I've created my Firebase cloud functions as follows:我创建了我的 Firebase 云函数,如下所示:

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

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

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

testfunc.js: ----------------------------------- 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 ----------------------- 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:然后我在常见的function中做了一个修改(John -> Peter):

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

Then, I just deployed function test1 again.然后,我再次部署了 function test1。

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.我最初的想法是,由于常见的 function 将在 function test1 更新时更新,因此 function test2 也应该隐式更新。 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.如果我想更新 function test2,我必须再次明确地进行部署(对于 test2)。

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.每个 function 部署彼此完全隔离 - 每个部署都有自己的代码副本。 Deploying a function will never alter the way another function works.部署 function 永远不会改变另一个 function 的工作方式。

If you want test2 to behave differently after modifying your code, you will have to deploy it again.如果您希望 test2 在修改代码后表现不同,则必须再次部署它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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