working test deploy config
This commit is contained in:
1 parent
c4cc268ea8
commit
f133d11123
18 files changed
+268
-19
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { APP_INITIALIZER, InjectionToken } from '@angular/core';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
export interface AppConfig {
|
||||
apiBaseUrl: string;
|
||||
}
|
||||
|
||||
export const APP_CONFIG = new InjectionToken<AppConfig>('appConfig');
|
||||
|
||||
const _appConfig: AppConfig = {
|
||||
apiBaseUrl: '',
|
||||
};
|
||||
|
||||
export function appConfigFactory(http: HttpClient) {
|
||||
return (): Promise<void> => {
|
||||
return lastValueFrom(http.get<AppConfig>('./config.json')).then(
|
||||
(config) => {
|
||||
Object.assign(_appConfig, config);
|
||||
},
|
||||
() => {
|
||||
// Keep defaults if config.json is not available (dev mode).
|
||||
},
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export const appConfigProvider = {
|
||||
provide: APP_CONFIG,
|
||||
useValue: _appConfig,
|
||||
};
|
||||
|
||||
export const appConfigInitProvider = {
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: appConfigFactory,
|
||||
deps: [HttpClient],
|
||||
multi: true,
|
||||
};
|
||||
|
||||
export function getAppConfig(): AppConfig {
|
||||
return _appConfig;
|
||||
}
|
||||
Reference in new issue
Block a user