如何从此处传递参数
export class NotificationModule implements NestModule{
public configure(consumer: MiddlewareConsumer) {
consumer.apply(AuthMiddleware).forRoutes(
{path: 'notification/create', method: RequestMethod.POST},
如何在这里使用传递的参数?
@Injectable()
export class AuthMiddleware implements NestMiddleware {
constructor(private readonly studentService: StudentService) {
}
async use(req: Request, res: Response, next: NextFunction) {
????????
}
发布于 2021-04-25 23:56:44
由于中间件是可注入的,因此您可以将选项作为任何其他提供程序传递,比如在模块here中传递选项的this one
或者使用create-nestjs-middleware-module
将中间件转换为模块
或者创建一个将返回中间件的混入。因此,您将传递像consumer.apply(CreateAuthMiddleware(opts))
这样的选项
https://stackoverflow.com/questions/67251958
复制相似问题