Skip to content

Value of config when DATABASE_URL and STORAGE_BUCKET_URL are not set, is not correct #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RezaRahmati opened this issue Dec 13, 2020 · 2 comments

Comments

@RezaRahmati
Copy link
Contributor

RezaRahmati commented Dec 13, 2020

Related issues

[REQUIRED] Version info

node: 12

firebase-functions: 3.13.0

firebase-tools: 8.19.0

firebase-admin: 9.4.2

[REQUIRED] Test case

[REQUIRED] Steps to reproduce

If we only set "GCLOUD_PROJECT" environment variable and then running admin.initializeApp(); you get below error

@firebase/database: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com

[REQUIRED] Expected behavior

Function setup with no error

[REQUIRED] Actual behavior

getting below error

@firebase/database: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com

Were you able to successfully deploy your functions?

no

Rootcause analysis

in

`${process.env.DATABASE_URL}` ||
and
in
`${process.env.STORAGE_BUCKET_URL}` ||

the current code is

			process.env.FIREBASE_CONFIG = JSON.stringify({
				databaseURL: `${process.env.DATABASE_URL}` ||
					`https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
				storageBucket: `${process.env.STORAGE_BUCKET_URL}` ||
					`${process.env.GCLOUD_PROJECT}.appspot.com`,
				projectId: process.env.GCLOUD_PROJECT,
			});

so if value of process.env.DATABASE_URL be undifined it will be converted to a string of 'undefined' which will result the databaseUrl or storgaeBucket become a string value of 'undefined'

Fix:
Below code fixes the issues, I didn't have access to create branch and submit PR

			process.env.FIREBASE_CONFIG = JSON.stringify({
				databaseURL: process.env.DATABASE_URL ||
					`https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
				storageBucket: process.env.STORAGE_BUCKET_URL ||
					`${process.env.GCLOUD_PROJECT}.appspot.com`,
				projectId: process.env.GCLOUD_PROJECT,
			});
@google-oss-bot
Copy link
Collaborator

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@RezaRahmati RezaRahmati changed the title Value of config when DATABASE_URL and STORAGE_BUCKET_URL are not set is not correct Value of config when DATABASE_URL and STORAGE_BUCKET_URL are not set, is not correct Dec 20, 2020
RezaRahmati added a commit to RezaRahmati/firebase-functions that referenced this issue Jan 4, 2021
RezaRahmati added a commit to RezaRahmati/firebase-functions that referenced this issue Jan 4, 2021
joehan added a commit that referenced this issue Jan 19, 2021
…URL (#840)

* #829 fixing issue reading env.DATABASE_URL and env.STORAGE_BUCKET_URL

* #829 revert space changes

Co-authored-by: joehan <joehanley@google.com>
joehan added a commit that referenced this issue Jan 19, 2021
@samtstern
Copy link
Contributor

This was closed by #840

samtstern pushed a commit that referenced this issue Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants