Reputation: 2230
I'm trying to separate deployment builds when using development vs public.
My .firebaserc
is set up like so:
{
"projects": {
"dev": "PROJECTNAME-development",
"public": "PROJECTNAME-public"
}
}
In one of my functions, I have to refer to the storage bucket:
const bucket = storage.bucket('PROJECTNAME-public.appspot.com')
At the moment, I have to change the name before I switch
I would like it so that when I deploy to dev, I can deploy to my dev project... something like this:
let bucket
if (currentAlias === public) {
bucket = storage.bucket('PROJECTNAME-public.appspot.com');
} else {
bucket = storage.bucket('PROJECTNAME-development.appspot.com');
}
I can't seem to find anything in the docs that would allow me to do something like this.
Upvotes: 1
Views: 265
Reputation: 317750
It sounds like you're trying to just access the default storage bucket for your project.
If you're using the Firebase Admin SDK, just initialize it with no parameters, and it will automatically pick up the name of the default bucket from the environment.
const admin = require('firebase-admin');
admin.initializeApp();
const bucket = admin.storage().bucket();
If you're using the Cloud Storage node SDK, you can manually pull the name of the bucket out of the environment:
const config = JSON.parse(process.env.FIREBASE_CONFIG)
const bucketName = config.storageBucket
const bucket = new Storage().bucket(bucketName) // version 2.x of the SDK
If you need to access some other value per project, you should use Firebase environment variables configured by the CLI at the time of deployment and read them using the SDK at runtime.
Upvotes: 2