Refactor app configuration to use hrefBase for base URL and improve provider imports
This commit is contained in:
@@ -1,32 +1,41 @@
|
|||||||
import {APP_INITIALIZER, ApplicationConfig, inject, provideZoneChangeDetection} from '@angular/core';
|
import {
|
||||||
|
APP_INITIALIZER,
|
||||||
|
ApplicationConfig,
|
||||||
|
inject,
|
||||||
|
provideZoneChangeDetection,
|
||||||
|
importProvidersFrom
|
||||||
|
} from '@angular/core';
|
||||||
import {provideRouter} from '@angular/router';
|
import {provideRouter} from '@angular/router';
|
||||||
|
import {BrowserModule} from '@angular/platform-browser';
|
||||||
|
import {APP_BASE_HREF} from '@angular/common';
|
||||||
import {routes} from './app.routes';
|
import {routes} from './app.routes';
|
||||||
import {provideHttpClient, withInterceptors} from '@angular/common/http';
|
import {provideHttpClient, withInterceptors} from '@angular/common/http';
|
||||||
import {provideAnimationsAsync} from '@angular/platform-browser/animations/async';
|
import {provideAnimationsAsync} from '@angular/platform-browser/animations/async';
|
||||||
import {authTokenInterceptor} from './interceptors/auth-token.interceptor';
|
import {authTokenInterceptor} from './interceptors/auth-token.interceptor';
|
||||||
import {AuthService} from './services/auth.service';
|
import {AuthService} from './services/auth.service';
|
||||||
import {catchError, firstValueFrom, of} from 'rxjs';
|
import {catchError, firstValueFrom, of} from 'rxjs';
|
||||||
|
import {environment} from '../environments/environment';
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [
|
providers: [
|
||||||
provideZoneChangeDetection({eventCoalescing: true}),
|
provideZoneChangeDetection({eventCoalescing: true}),
|
||||||
|
importProvidersFrom(BrowserModule),
|
||||||
|
{provide: APP_BASE_HREF, useValue: environment.hrefBase},
|
||||||
provideRouter(routes),
|
provideRouter(routes),
|
||||||
provideAnimationsAsync(),
|
provideAnimationsAsync(),
|
||||||
provideHttpClient(withInterceptors([
|
provideHttpClient(withInterceptors([authTokenInterceptor])),
|
||||||
authTokenInterceptor
|
|
||||||
])
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
provide: APP_INITIALIZER,
|
provide: APP_INITIALIZER,
|
||||||
multi: true,
|
multi: true,
|
||||||
useFactory: () => {
|
useFactory: () => {
|
||||||
const auth = inject(AuthService);
|
const auth = inject(AuthService);
|
||||||
return () => firstValueFrom(auth.bootstrapSession().pipe(
|
return () =>
|
||||||
catchError(err => of(null))
|
firstValueFrom(
|
||||||
)
|
auth.bootstrapSession().pipe(
|
||||||
);
|
catchError(() => of(null))
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}, provideAnimationsAsync()
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ export const environment = {
|
|||||||
production: true,
|
production: true,
|
||||||
apiUrl: '/gameovergne-api/api',
|
apiUrl: '/gameovergne-api/api',
|
||||||
psUrl: '/gameovergne-api/api/ps',
|
psUrl: '/gameovergne-api/api/ps',
|
||||||
indexBase: '/gameovergne/',
|
hrefBase: '/gameovergne/',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ export const environment = {
|
|||||||
production: false,
|
production: false,
|
||||||
apiUrl: 'http://localhost:3000/api',
|
apiUrl: 'http://localhost:3000/api',
|
||||||
psUrl: '/ps',
|
psUrl: '/ps',
|
||||||
indexBase: '/',
|
hrefBase: '/',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,10 +3,6 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Game Over'gne App</title>
|
<title>Game Over'gne App</title>
|
||||||
<script>
|
|
||||||
import {environment} from "./environments/environment.prod";
|
|
||||||
document.write('<base href="' + environment.indexBase + '">');
|
|
||||||
</script>
|
|
||||||
<base href="/">
|
<base href="/">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||||
|
|||||||
Reference in New Issue
Block a user