Today we have two different domains in our ecosystem. Our BFF should receive informations from those different endpoints.
If I add FirstService and SecondService in providers, both services get the same informations in HttpModule.registerAsync, but I must have two different baseUrl
Module.ts
@Module({
imports: [
HttpModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
timeout: 5000,
maxRedirects: 5,
baseURL: configService.get('SERVICE_URL_LEGACY'),
}),
}),
],
providers: [FirstService, SecondService],
controllers: [CampaignsController],
})
export class CampaignsModule {}
Controller must be something like this
Controller
export class CampaignsController {
constructor(
private readonly firstService: FirstService,
private readonly secondService: SecondService,
) {}
@Get('/review')
async getReview() {
const response = await this.firstService.getReview({});
const responseTwo = await this.secondService.getReview({});
}
There's only ever going to be one
HttpModuleinCampaignsModule, and it would have no way to know which service invoked it.If
FirstServiceandSecondServicewere in different modules, you could work. configure anHttpModulefor each one with the right settings. But that may not be right for you.Otherwise you'd just have to send the
baseURLin each time you use theHttpServicelike: