34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core';
|
|
import { provideRouter } from '@angular/router';
|
|
import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
|
import {
|
|
createInterceptorCondition,
|
|
IncludeBearerTokenCondition,
|
|
includeBearerTokenInterceptor,
|
|
INCLUDE_BEARER_TOKEN_INTERCEPTOR_CONFIG
|
|
} from 'keycloak-angular';
|
|
|
|
import { routes } from './app.routes';
|
|
import { provideKeycloakAngular } from './core/auth/keycloak.provider';
|
|
import { environment } from '../environments/environment';
|
|
|
|
const escapedMagazzinoApiBaseUrl = environment.magazzinoApiBaseUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
|
|
const magazzinoApiBearerCondition = createInterceptorCondition<IncludeBearerTokenCondition>({
|
|
urlPattern: new RegExp(`^${escapedMagazzinoApiBaseUrl}(/.*)?$`, 'i'),
|
|
bearerPrefix: 'Bearer'
|
|
});
|
|
|
|
export const appConfig: ApplicationConfig = {
|
|
providers: [
|
|
provideBrowserGlobalErrorListeners(),
|
|
provideRouter(routes),
|
|
provideKeycloakAngular(),
|
|
{
|
|
provide: INCLUDE_BEARER_TOKEN_INTERCEPTOR_CONFIG,
|
|
useValue: [magazzinoApiBearerCondition]
|
|
},
|
|
provideHttpClient(withInterceptors([includeBearerTokenInterceptor]))
|
|
]
|
|
};
|