mirror of https://github.com/abpframework/abp.git
5 changed files with 39 additions and 0 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'; |
|||
@ -0,0 +1,3 @@ |
|||
import { HttpContextToken } from '@angular/common/http'; |
|||
|
|||
export const IS_EXTERNAL_REQUEST = new HttpContextToken<boolean>(() => false); |
|||
Loading…
Reference in new issue