NestJS:记录 HttpService 调用的请求/响应?

Ian*_*son 11 javascript node.js typescript axios nestjs

我想知道是否可以HttpService使用HttpModule.

我曾经使用 AXIOS 的拦截器,HttpService包装了 axios 但我似乎无法在这里添加任何拦截器,似乎没有地方

HttpModule.register(...)
Run Code Online (Sandbox Code Playgroud)

然后我想到NestJS自带拦截器,想知道是否可以使用NestJS拦截器。

我不想将拦截器应用于控制器、服务,而是将其应用于HttpService

任何想法,有点迷失如何以 Nestjs 的方式做到这一点。

提前致谢

Kim*_*ern 13

直接通过公开HttpService其实例。有了它,您可以添加:axiosget axiosRef()axios interceptor

this.httpService.axiosRef.interceptors.request.use(config => console.log(config));
Run Code Online (Sandbox Code Playgroud)

例如,您可以在onModuleInit()您的AppModule.