Skip to content

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

Closed
@RezaRahmati

Description

@RezaRahmati

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,
			});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions