Skip to content
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

Feature request: Using Firestore emulator #2183

Closed
mparpaillon opened this issue Oct 1, 2019 · 17 comments
Closed

Feature request: Using Firestore emulator #2183

mparpaillon opened this issue Oct 1, 2019 · 17 comments

Comments

@mparpaillon
Copy link

mparpaillon commented Oct 1, 2019

Version info

**Angular: 8.2.8

**Firebase: 7.0.0

**AngularFire: 5.2.1

Feature Request Details

For now it seems impossible (at least I couldn't find how) to target the Firestore emulator locally.
When I run firebase emulators:start it's telling me firestore: Serving WebChannel traffic on at http://localhost:5003.
Changing the property "databaseURL" to http://localhost:5003 in the firebase config doesn't seem to work

So I guess that's not an option for now?

Thanks

@mparpaillon
Copy link
Author

mparpaillon commented Oct 1, 2019

Apparently I'm supposed to do that:

if (window.location.hostname === "localhost") {
  db.settings({
    host: "localhost:5003",
    ssl: false
  });
}

Is there a way to call .settings via angularfire2 ?

@jamesdaniels
Copy link
Member

You can provide FirestoreSettingsToken

@mparpaillon
Copy link
Author

I'm sorry could you elaborate please?

@GrandSchtroumpf
Copy link

GrandSchtroumpf commented Oct 4, 2019

You can have something like that in your app.module.ts :

@NgModule({
  providers: [
    {
      provide: FirestoreSettingsToken,
      useValue: environment.production ? undefined : {
        host: 'localhost:8081',
        ssl: false
      }
    }
  ],
  imports: [ ... ],
  declarations: [ ... ]
})

@mparpaillon
Copy link
Author

Merci @GrandSchtroumpf ! T'es un chef ;)

@rubenheymans
Copy link

host: 'localhost:8081',

thanks finally this took me hours before I realised the environment settings can't solve this

@assafsl
Copy link

assafsl commented Mar 23, 2020

FirestoreSettingsToken was replaced by SETTINGS in v6.0
see: https://github.com/angular/angularfire/blob/master/CHANGELOG.md

@Javison
Copy link

Javison commented Apr 17, 2020

Hi!
On firebase database:

databaseURL: "http://localhost:9000?ns=name-your-database",

firebase emulators:start --only database

Thanks!

@ghost
Copy link

ghost commented Apr 30, 2020

Thanks @GrandSchtroumpf for providing that snippet. The docs should be updated to include it probably.

@rami-alloush
Copy link

rami-alloush commented Apr 30, 2020

This works in environment.ts without raising any errors.

export const environment = {
    production: false,
    firebaseConfig: {
        host: 'localhost:8081',
        ssl: false,
        apiKey: '<your-key>',
        databaseURL: 'http://localhost:9000?ns=<your-id>',
        projectId: '<your-id>',
        appId: '<your-id>',
        measurementId: '<your-id>',
    },
};

@patbrennan
Copy link

@rami-alloush I'm trying to get this to work with the environment.ts file, no joy. The providers method in app.module.ts worked, but I'm wondering - what exactly should go after the ?ns= in the databaseURL? Editing the environments file seems like a much cleaner way to do this.

export const environment = {
  production: false,
  firebase: {
    host: 'localhost:8080',
    ssl: false,
    apiKey: '<my-key>',
    databaseURL: 'http://localhost:8080?ns=...', // what goes after ns? - not working for me
    projectId: 'aerotools-dev',
    appId: '<my-app-id>',
    measurementId: '<my-measurement-id>',
  },
};

Output from running firebase emulators:start --only firestore:

 ✔  All emulators ready! View status and logs at http://localhost:5002 │

│ Emulator  │ Host:Port      │ View in Emulator UI             │
│ Firestore │ localhost:8080 │ http://localhost:5002/firestore │

@tzoratto
Copy link

hi @patbrennan, as I understand it, the databaseURL property is only used for firebase database and not Firestore. If you only use Firestore, the properties you need are host and ssl, but these properties cannot be set using the firebase config.
These properties have to be set as explained in #2183 (comment) (and don't forget to replace FirestoreSettingsToken by SETTINGS since v6 as assafsl said)

@adamgen
Copy link

adamgen commented Jun 11, 2020

Thanks everyone, I had the same issue and this works for me as expected:

{
    provide: SETTINGS,
    useValue: environment.production ? undefined : {
        host: 'localhost:8080',
        ssl: false
    }
}

@MichaelN2004
Copy link

Have look at the example file of the project: app.module.ts. This works for me.
Import:
import { AngularFirestoreModule, SETTINGS as FIRESTORE_SETTINGS } from '@angular/fire/firestore';
Added Provider:
{ provide: FIRESTORE_SETTINGS, useFactory: () => shouldUseEmulator() ? { host: 'localhost:8080', ssl: false } : {} }
shouldUseEmulator can be also found in the source.

@blasco
Copy link

blasco commented Oct 12, 2020

How about the callable firebase functions? Is there a way to test them locally?

@GrandSchtroumpf
Copy link

@blasco It's in the documentation here.

@gino-m
Copy link

gino-m commented Nov 23, 2020

Edit:
Removing my previous solution, which wasn't working when I tried it in a new branch; I likely missed a piece or misrepresented what's needed for this to work. Better to refer directly to the relevant AngularFire docs, which I discovered after my original post:

Using emulators:
https://github.com/angular/angularfire/blob/master/docs/emulators/emulators.md

Example:
https://github.com/angular/angularfire/blob/master/sample/src/app/app.module.ts

HTH! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests