Skip to content

Commit

Permalink
fix(env): try FIREBASE_CONFIG json when GCLOUD_PROJECT unset
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed May 7, 2021
1 parent c6f25f2 commit 92cfb16
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions functions/__env.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// setup server and app options from Functions config (and mocks)
const { GCP_PROJECT, GCLOUD_PROJECT } = process.env
const projectId = GCP_PROJECT || GCLOUD_PROJECT
const { GCLOUD_PROJECT, FIREBASE_CONFIG, FUNCTION_REGION } = process.env
const { pkg, server } = require('firebase-functions').config()

let projectId = GCLOUD_PROJECT
if (FIREBASE_CONFIG) {
projectId = JSON.parse(FIREBASE_CONFIG).projectId
}
const region = FUNCTION_REGION || 'us-central1'
const functionName = server.functionName || 'app'

module.exports = {
functionName,
operatorToken: server && server.operator_token,
baseUri: (server && server.base_uri) ||
`https://us-central1-${projectId}.cloudfunctions.net/${functionName}`,
`https://${region}-${projectId}.cloudfunctions.net/${functionName}`,
hostingUri: `https://${projectId}.web.app`,
pkg: {
...pkg
Expand Down

0 comments on commit 92cfb16

Please sign in to comment.