File

libs/nx/src/executors/shared/metadata-utils/__test/my-team-plugin-lib/src/lib/language-interceptor/language-interceptor.ts

Index

Methods

Constructor

constructor(locale: string, options?: LanguageInterceptorPluginOptions)
Parameters :
Name Type Optional
locale string No
options LanguageInterceptorPluginOptions Yes

Methods

intercept
intercept(request: HttpRequest<>, next: HttpHandler)
Parameters :
Name Type Optional
request HttpRequest<> No
next HttpHandler No
Returns : Observable<HttpEvent<>>


type: plugin title: Language Interceptor description: 'This description says everything I need to know about the plugin'

import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Inject, Injectable, LOCALE_ID } from '@angular/core';
import { Observable } from 'rxjs';
import { LanguageInterceptorPluginOptions } from './language-interceptor.module';
import { LANGUAGE_INTERCEPTOR_PLUGIN_OPTIONS } from './tokens';

@Injectable()
export class LanguageInterceptor implements HttpInterceptor {
  constructor(
    @Inject(LOCALE_ID) private locale: string,
    @Inject(LANGUAGE_INTERCEPTOR_PLUGIN_OPTIONS) private options?: LanguageInterceptorPluginOptions
  ) {}

  intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
    const clonedRequest = request.clone({
      headers: request.headers.set('Language', this.options?.language || this.locale)
    });

    console.log('LanguageInterceptor::LanguageInterceptorPluginOptions', this.options);

    // send the cloned request with the Language header to the next handler
    return next.handle(clonedRequest);
  }
}

results matching ""

    No results matching ""