import { Injectable } from "@angular/core";
import { HttpRequest, HttpHandler, HttpEvent } from "@angular/common/http";
import { Observable } from "rxjs";

@Injectable()
export class ApiInterceptor {
  baseApi = "https://api-roadreport.pisdev.my.id";

  intercept(
    request: HttpRequest<unknown>,
    next: HttpHandler
  ): Observable<HttpEvent<unknown>> {
    const match = /^(\/(api|auth).+)/;
    const clientReq = request.clone({
      url: request.url.replace(match, `${this.baseApi}$1`),
    });

    return next.handle(clientReq);
  }
}
