My nestjs system is a system that connects to multiple systems via API calls.
For each system, I created a Module to handle their processes. Each of these modules imports HttpModule
.
I want to have separate Axios interceptors for each of these modules' HttpModule.
This is my attempt to test the functionality:
on a.module.ts
:
@Module({
imports: [
HttpModule,
// Other imports
],
// controllers, providers and exports here
})
export class ModuleA implements OnModuleInit {
constructor(private readonly httpService: HttpService) { }
public onModuleInit() {
this.httpService.axiosRef.interceptors.request.use(async (config: Axios.AxiosRequestConfig) => {
console.log('Module A Interceptor');
return config;
});
}
}
The module class for Module B is similar, with a different message in the console.log
call.
I tried making a http call to System B using a service in Module B, but both messages are displayed in the console.
I figured that the http module is a singleton across the system, so how do I instantiate a separate HttpModule
for Module A and Module B?