Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import { Injectable, Inject, Optional } from '@angular/core';
import { HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
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