å ¬éæ¥: 2021-09-04
æŽæ°æ¥: 2021-09-04
firebase init
ã§ãããžã§ã¯ãã®åæåãå®äºæžã¿ïŒfunctionsãã£ã¬ã¯ããªãããïŒãŸãã¯ç°å¢å€æ°ãFirebase CLIã§èšå®ããŸãã
$ firebase functions:config:set <project id>.<key>=<value>
ex. project idã"sample-app"ã§secretããŒã«å€ãèšå®ããå Žåã
$ firebase functions:config:set sample-app.secret="apisecret"
ããã§ã<key>ã«ã¯å€§æåã䜿ããªãã®ã§æ³šæãå¿
èŠã§ãã
次ã«.runtimeconfig.json
ãçæããŸãã
$ firebase functions:config:get > .runtimeconfig.json
ããã§èšå®ã¯å®äºã§ããããŸãããã°ä»¥äžã®ãããªãã¡ã€ã«ãåºåãããã¯ãã§ãã
{
"sample-app": {
"secret": "apisecret",
}
}
åœç¶ã®ããšã§ãããGitã䜿çšããŠããå Žåã¯.runtimeconfig.json
ã.gitignore
ã«å«ããŠãããŸãããã
次ã«ãã³ãŒãäžã§ç°å¢å€æ°ã䜿çšããŸãã
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
// init
admin.initializeApp();
const config = functions.config()
const env = config["sample-app"]
console.log(env.secret) // output: apisecret
ããã§ç°å¢å€æ°ã䜿ããããã«ãªããŸããïŒ
ãããžã§ã¯ããªã¹ãã®è¡šç€º
$ firebase projects:list
åãããžã§ã¯ãã®ç°å¢å€æ°ãªã¹ãã衚瀺
$ firebase functions:config:get