Closed 2Kable closed 4 years ago
Are you able to globally bind interceptors and guards using custom providers, e.g.
{
provide: APP_INTERCEPTOR,
useClass: InterceptorClass
}
That's how i'm currently doing it. But the APP_INTERCEPTOR is set using useGlobalInterceptors
at NestFactory.createApplicationContext
time
NestFactory.createApplicationContext -> NestFactory.initialize -> Scanner.applyApplicationProviders -> Scanner.getApplyProvidersMap -> it then adds the global interceptor to the ApplicationConfig
but the ApplicationConfig instance is not used when running connectMicroservice()
, it create a new one
Oh, that's super interesting. I haven't had a chance to play around with Hybrid Applications much, so that's good to know.
Maybe we can add an additional argument to the connectMicroservice()
method(?). What about something like this:
const transportOptions = {
transport: Transport.GRPC,
options: {}
};
app.connectMicroservice(transportOptions, { inheritAppConfig: true });
Looks good to me. I can start working on the PR if the specs are a go
Out of curiosity, would this also affect apps with WebSockets? I'm working on a logging library and using the custom provider for globally binding interceptors doesn't seem to bind for gateways. Only HTTP calls.
I not familiar with WS implementation, but after a quick look I don't think this is the same issue
Hi, i'm also facing this same issue, my global interceptor is ignored in microservices,
I see the pull request has been made, is there anything I can help to make it merge? Thank you
Hi, PR is ready, but I'm struggling with the test coverage. As far as I know it's just because I added lines, but can't actually covers them So feel free to contribute/help
@2Kable I'll take care of this, no worries! Thanks
Added in 7.1.0. Thanks!
Feature Request
related to: https://github.com/nestjs/nest/issues/4112
Is your feature request related to a problem? Please describe.
We are running NestJS container that run a HTTP/GraphQL api, but also process GRPC, Queuing requests, in the same nestjs instance
I would like to run grpc alongside the graphql/http instance, and being able to intercept all request to log them, whether they are from GRPC or HTTP, using
app.useGlobalInterceptors
Describe the solution you'd like
We fixed it by patching nest source code and passing the
NestApplication
config in theNestMicroservice
constructorBut this would lead to a huge breaking change for current application that wants a separate configuration.
I would suggest an optional argument/property to pass to the
connectMicroservice
function to use or provide an existingApplicationConfig
instanceAnother solution could be adding a method to attach a
NestMicroservice
instance to the NestApplication without relying on connectMicroserviceWhat is the motivation / use case for changing the behavior?
I would expect that hybrid application can share the same
ApplicationConfig
. Not being able to set global guard/interceptors for nest-grpc running in an hybrid application, greatly reduce the experience of it.