firebase-tools:
6.3.1
Platform:
macOS
Access environment configuration in a function
https://firebase.google.com/docs/functions/config-env#access_environment_configuration_in_a_function
Set a function config key in local machine:
firebase functions:config:set client.host=https://project-name.firebaseapp.com
Verify it is set in local system:
firebase functions:config:get
which produces following output:
{
"client": {
"host": "https://project-name.firebaseapp.com"
}
}
index.ts (TypeScript) by writing values to console and running the function locally:index.ts file content:
import * as functions from 'firebase-functions';
console.log('functions.config(): ');
console.log(JSON.stringify(functions.config()));
Output of sudo firebase serve --only functions :
info: functions.config():
info: {"client":{"host":"https://project-name.firebaseapp.com"}}
firebase deploy --only functions
functions: Finished running predeploy script.
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (37.97 KB) for uploading
✔ functions: functions folder uploaded successfully
i functions: updating Node.js 6 function myFunction(us-central1)...
✔ functions[myFunction(us-central1)]: Successful update operation.
✔ Deploy complete!
Same as above
The console output in the cloud should be matching with the locally served functions.config() value.
The console output in the cloud is NOT matching with the locally served functions.config() value.
Local value:
info: functions.config():
info: {"client":{"host":"https://project-name.firebaseapp.com"}}
Cloud value:
functions.config():
{}
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "./node_modules/.bin/tslint -p tslint.json && ./node_modules/.bin/tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/index.js",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.16.4",
"fast-xml-parser": "^3.12.10",
"firebase-admin": "7.0.0",
"firebase-functions": "^2.2.0",
"rxjs": "^6.3.3"
},
"devDependencies": {
"tslint": "~5.8.0",
"typescript": "^3.3.1"
},
"private": true
}
Hi @AmitThakur,
Sorry to hear about your issue. I tried reproducing your issue but was unable to do so on my end, but there were issues with Functions earlier (see status dashboard). Can you try redeploying now to see if it is resolved?
Hey @AmitThakur. We need more information to resolve this issue but there hasn't been an update in 7 days. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
I still see the same issue after redeploying just a while ago:
Local Log Value
info: functions.config():
info: {"client":{"host":"https://project-name.firebaseapp.com"}}
Cloud Log Value
functions.config():
{}
Can you provide the .js file that is the output of your build step? If something odd is happening during the build, that may be causing the issue. (I'm having trouble replicating as well, for what that's worth)
Since there haven't been any recent updates here, I am going to close this issue.
@AmitThakur if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.
oss-bot, you were a little over-zealous....
@bkendall I think I found the root cause of the behaviour, and it was my ignorance.
Actually, I'm using multiple Firebase projects with the same project directory with firebase aliases.
So there are three environments (and thus, 3 projects): prod, stage, test. prod is the default one, so every time I was making firebase functions:config:set ... for test project, I wasn't mentioning -P test alias in the command, so it was setting functions config for the default project, here prod. I verified it by looking at logs of the prod project in the firebase console (https://console.firebase.google.com), and I found the config set there correctly.
So, I added -P <alias_name> in the command so it is now working with:
firebase -P test functions:config:set ...
and I verified by deploying to all different projects.
Please feel free to close the issue as not-a-bug. Thanks!
Great, I'm glad you got it working!
Most helpful comment
@bkendall I think I found the root cause of the behaviour, and it was my ignorance.
Actually, I'm using multiple Firebase projects with the same project directory with firebase aliases.
So there are three environments (and thus, 3 projects):
prod,stage,test.prodis the default one, so every time I was makingfirebase functions:config:set ...fortestproject, I wasn't mentioning-P testalias in the command, so it was setting functions config for the default project, hereprod. I verified it by looking at logs of theprodproject in the firebase console (https://console.firebase.google.com), and I found the config set there correctly.So, I added
-P <alias_name>in the command so it is now working with:firebase -P test functions:config:set ...and I verified by deploying to all different projects.
Please feel free to close the issue as
not-a-bug. Thanks!