Skip to content

Commit 92cfb16

Browse files
committed
fix(env): try FIREBASE_CONFIG json when GCLOUD_PROJECT unset
1 parent c6f25f2 commit 92cfb16

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

functions/__env.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
// setup server and app options from Functions config (and mocks)
2-
const { GCP_PROJECT, GCLOUD_PROJECT } = process.env
3-
const projectId = GCP_PROJECT || GCLOUD_PROJECT
2+
const { GCLOUD_PROJECT, FIREBASE_CONFIG, FUNCTION_REGION } = process.env
43
const { pkg, server } = require('firebase-functions').config()
4+
5+
let projectId = GCLOUD_PROJECT
6+
if (FIREBASE_CONFIG) {
7+
projectId = JSON.parse(FIREBASE_CONFIG).projectId
8+
}
9+
const region = FUNCTION_REGION || 'us-central1'
510
const functionName = server.functionName || 'app'
611

712
module.exports = {
813
functionName,
914
operatorToken: server && server.operator_token,
1015
baseUri: (server && server.base_uri) ||
11-
`https://us-central1-${projectId}.cloudfunctions.net/${functionName}`,
16+
`https://${region}-${projectId}.cloudfunctions.net/${functionName}`,
1217
hostingUri: `https://${projectId}.web.app`,
1318
pkg: {
1419
...pkg

0 commit comments

Comments
 (0)