mirror of https://github.com/abpframework/abp.git
committed by
GitHub
17 changed files with 117 additions and 53 deletions
@ -0,0 +1,30 @@ |
|||||
|
import { HttpClient, HttpContext, HttpRequest } from '@angular/common/http'; |
||||
|
import { Injectable } from '@angular/core'; |
||||
|
import { Observable } from 'rxjs'; |
||||
|
import { IS_EXTERNAL_REQUEST } from '../tokens/http-context.token'; |
||||
|
|
||||
|
// source : https://github.com/armanozak/demo-angular-server-specific-interceptors
|
||||
|
@Injectable({ |
||||
|
providedIn: 'root', |
||||
|
}) |
||||
|
export class ExternalHttpClient extends HttpClient { |
||||
|
override request( |
||||
|
first: string | HttpRequest<any>, |
||||
|
url?: string, |
||||
|
options: RequestOptions = {}, |
||||
|
): Observable<any> { |
||||
|
if (typeof first === 'string') { |
||||
|
this.#setPlaceholderContext(options); |
||||
|
return super.request(first, url, options); |
||||
|
} |
||||
|
|
||||
|
this.#setPlaceholderContext(first); |
||||
|
return super.request(first); |
||||
|
} |
||||
|
#setPlaceholderContext(optionsOrRequest: { context?: HttpContext }) { |
||||
|
optionsOrRequest.context ??= new HttpContext(); |
||||
|
optionsOrRequest.context.set(IS_EXTERNAL_REQUEST, true); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
type RequestOptions = Parameters<HttpClient['request']>[2]; |
||||
@ -0,0 +1 @@ |
|||||
|
export * from './http.client'; |
||||
@ -1,8 +1,7 @@ |
|||||
import { Provider } from "@angular/core"; |
import { Provider } from '@angular/core'; |
||||
import { INCUDE_LOCALIZATION_RESOURCES_TOKEN } from "../tokens/include-localization-resources.token"; |
import { INCUDE_LOCALIZATION_RESOURCES_TOKEN } from '../tokens/include-localization-resources.token'; |
||||
|
|
||||
export const IncludeLocalizationResourcesProvider: Provider = { |
export const IncludeLocalizationResourcesProvider: Provider = { |
||||
provide: INCUDE_LOCALIZATION_RESOURCES_TOKEN, |
provide: INCUDE_LOCALIZATION_RESOURCES_TOKEN, |
||||
useValue: false, |
useValue: false, |
||||
}; |
}; |
||||
|
|
||||
|
|||||
@ -1,3 +1,3 @@ |
|||||
export * from './cookie-language.provider'; |
export * from './cookie-language.provider'; |
||||
export * from './locale.provider'; |
export * from './locale.provider'; |
||||
export * from './include-localization-resources.provider'; |
export * from './include-localization-resources.provider'; |
||||
|
|||||
@ -0,0 +1,3 @@ |
|||||
|
import { HttpContextToken } from '@angular/common/http'; |
||||
|
|
||||
|
export const IS_EXTERNAL_REQUEST = new HttpContextToken<boolean>(() => false); |
||||
@ -1,3 +1,5 @@ |
|||||
import { InjectionToken } from "@angular/core"; |
import { InjectionToken } from '@angular/core'; |
||||
|
|
||||
export const INCUDE_LOCALIZATION_RESOURCES_TOKEN = new InjectionToken<boolean>('INCUDE_LOCALIZATION_RESOURCES_TOKEN'); |
export const INCUDE_LOCALIZATION_RESOURCES_TOKEN = new InjectionToken<boolean>( |
||||
|
'INCUDE_LOCALIZATION_RESOURCES_TOKEN', |
||||
|
); |
||||
|
|||||
Loading…
Reference in new issue