Skip to content

Instantly share code, notes, and snippets.

@dev-sampsonorson
Forked from nartc/app.module.ts
Created June 14, 2023 08:42
Show Gist options
  • Save dev-sampsonorson/4b5dc0eb5bb571ce923cdee9b9a36521 to your computer and use it in GitHub Desktop.
Save dev-sampsonorson/4b5dc0eb5bb571ce923cdee9b9a36521 to your computer and use it in GitHub Desktop.
@NgModule({
imports: [OAuthModule.forRoot({...})] // <-- how to use the configuration.json here
})
export class AppModule {
constructor(@Inject(AppConfig) private readonly appConfig: AppConfiguration) {} // I can inject
}
{
"apiBaseUrl": "https://localhost:5301"
}
export interface AppConfiguration {
apiBaseUrl: string;
}
export const AppConfig = new InjectionToken<AppConfiguration>('@@appConfiguration');
(async () => {
try {
const config: AppConfiguration = await fetch('assets/configuration.json').then(res => res.json());
if (config.production) {
console.log('Running in production mode');
enableProdMode();
}
platformBrowserDynamic([
{ provide: AppConfig, useValue: config }
]).bootstrapModule(AppModule)
.catch(err => console.error(err));
} catch (e) {
console.error('Error initializing', e);
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment