Skip to content
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

Suggestion NestFastifyPlugin #8964

Closed
1 task done
winverse opened this issue Jan 19, 2022 · 1 comment
Closed
1 task done

Suggestion NestFastifyPlugin #8964

winverse opened this issue Jan 19, 2022 · 1 comment
Labels
needs triage This issue has not been looked into type: enhancement 🐺

Comments

@winverse
Copy link

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

When use fastify adapter, middleware type not matched #8837

and middleware concept is diluted in fastify

I want use fastify decorator and hooks with other provider as dependency injection

it is possible?

Describe the solution you'd like

// token.plugin.ts
import { NestFastifyPlugin } from '@nest/fastify-platform';
import { TokenService } from '@provider/token.service';

@Injectable()
export class TokenPlugin implements NestFastifyPlugin {
   constructor(private tokenService: TokenService) {};
   callback(fastify, option, done) {
      fastify.decorateRequest('user', null);
      fastify.addHook('preHandler', async (reqeust, reply) => {
        // do something
        // maybe get cookie from request.cookies and tokenService method call
      });

      done();
  }
}


// app.module.ts
  @Module({
    imports: [
      NestConfigModule,
      ConfigModule,
    ],
    providers: [
      {
        provide: APP_PRUGIN,
        useClass: TokenPlugin,
      },
    ],
  })
  export class AppModule {}

Teachability, documentation, adoption, migration strategy

In nestjs document, write about fastify plugin as provider.

What is the motivation / use case for changing the behavior?

a person want to do something before or after API calls using the fastify life cycle (which is different from the interceptor).

But he/she don't just use the hook
It can be used with other existing providers as dependency injection.

and the module imported in app.module.ts
so everything is alright.

@winverse winverse added needs triage This issue has not been looked into type: enhancement 🐺 labels Jan 19, 2022
@kamilmysliwiec
Copy link
Member

Please, use our Discord channel (support) for such questions (this is already doable with Nest). We are using GitHub to track bugs, feature requests, and potential improvements.

@nestjs nestjs locked and limited conversation to collaborators Jan 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue has not been looked into type: enhancement 🐺
Projects
None yet
Development

No branches or pull requests

2 participants