如何在proxy.conf.json angular中使用拦截器

我需要对请求使用拦截器。而且我还需要使用 proxy.conf.json 文件来避免 CORS 错误。如何同时使用拦截器和proxy.conf.json?

{
  "/api/*": {
    "target": "http://localhost:9000","secure": false,"logLevel": "debug"
  }
}

拦截器

@Injectable()
export class EndpointInterceptor implements HttpInterceptor {

  private static addRequestId(request: HttpRequest<any>): HttpRequest<any> {
    return request.clone({
      withCredentials: true,headers: request.headers
    });
  }
  intercept(req: HttpRequest<any>,next: HttpHandler): Observable<HttpEvent<any>> {
    if (req.url.startsWith('./assets/')) {
      return next.handle(req);
    }

    req = EndpointInterceptor.addRequestId(req);

    console.log(environment.dev);

    return next.handle(req.clone({ url: `${ environment.dev }${ req.url }` }));
  }
}
bbsoft123 回答:如何在proxy.conf.json angular中使用拦截器

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1232.html

大家都在问