nestjs-slack
nestjs-slack copied to clipboard
How to instantiate the SlackService class in main.ts
Hi.
I hope you are well.
In the main.ts I want to pass the SlackService configuration to the global exception filter which receives that class in the constructor, but I don't understand the way to achieve this.
public async bootstrap(): Promise<INestApplication> {
this.app = await NestFactory.create(AppModule, { cors: true });
const configService = await this.app.resolve(ConfigService);
this.setGlobalFilters(configService);
await this.listen(configService.get('app.port'));
return this.app;
}
public setGlobalFilters(configService: ConfigService) {
const httpAdapter: HttpAdapterHost =
this.app.get<HttpAdapterHost>(HttpAdapterHost);
const slackService = new SlackService({
type: 'webhook',
webhookOptions: {
url: configService.get('SLACK_WEBHOOK_URL'),
},
});
this.app.useGlobalFilters(
new AllExceptionsFilter(httpAdapter, slackService),
);
}
Hello 👋
As far as I can see, this should work. I do the same in my applications, but I don't use the useGlobalFilters
.
{
provide: APP_FILTER,
useClass: AllExceptionsFilter,
},
Maybe something for you too?
Closing this as stale, but feel free to leave me a note if you wanna pick this up :)