Skip to content

Instantly share code, notes, and snippets.

@dancornilov
Last active May 11, 2021 13:05
Show Gist options
  • Save dancornilov/f7d53840992be53b4b14185dfc46659a to your computer and use it in GitHub Desktop.
Save dancornilov/f7d53840992be53b4b14185dfc46659a to your computer and use it in GitHub Desktop.
Environment HttpInterceptor
import {Injectable} from '@angular/core';
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
import {Observable} from 'rxjs/Observable';
import {environment} from '../../../environments/environment';
@Injectable()
export class EnvironmentInterceptorService implements HttpInterceptor {
constructor() {
}
public intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const update = {} as any;
update.url = `${environment.serverName}/${req.url}`;
return next.handle(req.clone(update));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment