firebase / firebase-admin-go

Firebase Admin Go SDK
Apache License 2.0
1.13k stars 244 forks source link

Unable to connect to realtime db hosted in europe west #415

Closed Jo3116 closed 3 years ago

Jo3116 commented 3 years ago

The problem

Cannot connect to a realtime Db hosted in Europe west because of invalid database URL. I was attempting to use a url ending in europe-west1.firebasedatabase.app to connect to a Europe hosting but received the error invalid database URL: want host: "firebaseio.com

Steps to reproduce:

Attempt to create a new client using app.DatabaseWithURL passing in a Europe url ending in europe-west1.firebasedatabase.app

Relevant Code:


func NewFirebaseConnection(ctx context.Context, url string) FirebaseConnection {
    var conn FirebaseConnection
    conn.app = initializeApp(ctx)
    conn.client = initializeClient(ctx, conn.app, url)
    return conn
}

// initializeApp creates a firebase app object
func initializeApp(ctx context.Context) *firebase.App {
    // Initialize the app with a service account, granting admin privileges
    app, err := firebase.NewApp(ctx, nil)
    if err != nil {
        log.Fatalln("Error initializing app:", err)
    }

    return app
}

// initializeClient creates a firebase client object
func initializeClient(ctx context.Context, app *firebase.App, url string) *db.Client {
    client, err := app.DatabaseWithURL(ctx, url)
    if err != nil {
        log.Fatalln("Error initializing database client:", err)
    }

    return client
}
google-oss-bot commented 3 years ago

I found a few problems with this issue:

hiranya911 commented 3 years ago

This requires a fix similar to https://github.com/firebase/firebase-admin-python/pull/517

thameezb commented 3 years ago

Hitting the same issue