-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathapp.config.ts
More file actions
64 lines (57 loc) · 1.65 KB
/
app.config.ts
File metadata and controls
64 lines (57 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright (c) 2025 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. - initial API and implementation
*
*/
import {
ApplicationConfig,
inject,
Injectable,
provideAppInitializer,
provideZoneChangeDetection,
} from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
import { HttpClient, provideHttpClient } from '@angular/common/http';
import { firstValueFrom } from 'rxjs';
import { APP_BASE_HREF } from '@angular/common';
@Injectable({
providedIn: 'root',
})
class BaseHrefService {
private readonly http = inject(HttpClient);
private baseHref = '/';
async load() {
try {
this.baseHref = (
await firstValueFrom(this.http.get('config/APP_BASE_HREF.txt', { responseType: 'text' }))
).replace(/\n/g, '');
} catch {
console.debug('No base href config found. Default is "/"');
}
}
get(): string {
return this.baseHref;
}
}
export const appConfig: ApplicationConfig = {
providers: [
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(routes),
provideHttpClient(),
provideAppInitializer(() => inject(BaseHrefService).load()),
{
provide: APP_BASE_HREF,
useFactory: (svc: BaseHrefService) => svc.get(),
deps: [BaseHrefService],
},
],
};