Skip to content

Instantly share code, notes, and snippets.

@cyrilletuzi
Last active September 12, 2020 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cyrilletuzi/e0ef88f5687cab486828ffa9f9f1e852 to your computer and use it in GitHub Desktop.
Save cyrilletuzi/e0ef88f5687cab486828ffa9f9f1e852 to your computer and use it in GitHub Desktop.
import { Injectable, Inject, Optional } from '@angular/core';
import { HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
@Injectable()
export class UniversalInterceptor implements HttpInterceptor {
constructor(@Optional() @Inject('serverUrl') protected serverUrl: string) {}
intercept(req: HttpRequest<any>, next: HttpHandler) {
const serverReq = !this.serverUrl ? req : req.clone({
url: `${this.serverUrl}${req.url}`
});
return next.handle(serverReq);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment