-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to register multiples HttpModule #1098
Comments
Thanks for reporting. Fixed, I'll deploy soon. |
Fixed in the latest patch version:) |
@kamilmysliwiec It seems like I have the same issue: @Module({
imports: [HttpModule.register({
baseURL: 'http://b.com',
})],
providers: [MailerService],
exports: [MailerService]
})
export class MailerModule {} @Module({
imports: [HttpModule.register({
baseURL: 'http://a.com',
})],
providers: [ParserService],
exports: [ParserService]
})
export class ParserModule {} When making request in MailerService with HttpService it uses http://a.com (should http://b.com). Using nest v6.1.1, node v10.15.3, linux mint 19 cinnamon. |
I've encountered the same behavior: @module({ @module({ |
Hi @kamilmysliwiec is there any update on this? I'm also facing the same issue @Module({
providers: [MeService],
controllers: [MeController],
imports: [
HttpModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
baseURL: configService.get('app').profileBaseUrl,
}),
inject: [ConfigService],
}),
HttpModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
baseURL: configService.get('app').authBaseUrl,
}),
inject: [ConfigService],
}),
],
})
export class MeModule {} |
Could you please create a separate issue + provide a minimal reproduction repo? @jpgarcia |
I've just created a new repo. Before creating the new issue let me know if what we can achieve is possible. https://github.com/jpgarcia/nestjs-multiple-http-modules Files involved are: Notice the baseURL are the same in the console output: HttpService Instance #1 HttpService {
instance:
{ [Function: wrap]
request: [Function: wrap],
delete: [Function: wrap],
get: [Function: wrap],
head: [Function: wrap],
options: [Function: wrap],
post: [Function: wrap],
put: [Function: wrap],
patch: [Function: wrap],
defaults:
{ adapter: [Function: httpAdapter],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers: [Object],
baseURL: 'https://docs.nestjs.com' },
interceptors:
{ request: [InterceptorManager],
response: [InterceptorManager] } } }
HttpService Instance #2 HttpService {
instance:
{ [Function: wrap]
request: [Function: wrap],
delete: [Function: wrap],
get: [Function: wrap],
head: [Function: wrap],
options: [Function: wrap],
post: [Function: wrap],
put: [Function: wrap],
patch: [Function: wrap],
defaults:
{ adapter: [Function: httpAdapter],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers: [Object],
baseURL: 'https://docs.nestjs.com' },
interceptors:
{ request: [InterceptorManager],
response: [InterceptorManager] } } } |
Well, not really. If you import |
@kamilmysliwiec you are right, my bad! Do you have any suggestion to inject two instances of an |
@jpgarcia In this case, I've created two separated modules and inject both HTTP services from those modules |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm submitting a...
Current behavior
When the HttpModule is imported into multiple modules, the first record of it overlaps all others, as if it were global.
Expected behavior
Each record gets stuck in its context.
Minimal reproduction of the problem with instructions
Make request with HttpService in AService with this.http.get('/whatever'):
Make request with HttpService in BService with this.http.get('/whatever'):
expected b.com/whatever
What is the motivation / use case for changing the behavior?
Creation of multiple services that connects to other apis.
Example:
FirstExternalApiModule -> FirstExternalApiService -> Http request -> First external api
SecondExternalApiModule -> SecondExternalApiService -> Http request -> Second external api
Environment
The text was updated successfully, but these errors were encountered: