I want to load the firebaseConfig asynchronously because I want to seperate config from artifact, to be able to have a clean CI/CD pipeline (build once, run on any environment, get config from server).
But to use firebase I need to call provideFirebaseApp(() => initializeApp(firebaseConfig)) inside of the imports of my AppModule. How can I do this if firebaseConfig must be loaded asynchronously?
What I would like to do:
let config: { firebase: any };
function initializeAppFactory(httpClient: HttpClient): () => Observable<any> {
return () => httpClient.get('https://myserver.com/api/config').pipe(c => config = c)
}
@NgModule({
imports: [
BrowserModule,
HttpClientModule,
provideFirebaseApp(() => {
return initializeApp(config.firebase);
// THIS DOES NOT WORK, because the APP_INITIALIZER is async! How can we also make this import async?!?
})],
declarations: [AppComponent],
bootstrap: [AppComponent],
providers: [{
provide: APP_INITIALIZER,
useFactory: initializeAppFactory,
deps: [HttpClient],
multi: true,
}],
})