本文整理汇总了TypeScript中@nestjs/common.MiddlewaresConsumer.apply方法的典型用法代码示例。如果您正苦于以下问题:TypeScript MiddlewaresConsumer.apply方法的具体用法?TypeScript MiddlewaresConsumer.apply怎么用?TypeScript MiddlewaresConsumer.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@nestjs/common.MiddlewaresConsumer
的用法示例。
在下文中一共展示了MiddlewaresConsumer.apply方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: configure
configure(consumer: MiddlewaresConsumer): void {
consumer.apply(CorsMiddleware).forRoutes({
path: '/*'
});
consumer.apply(OrgsMiddleware).forRoutes({
path: '/*'
});
consumer.apply(AuthMiddleware).forRoutes({
path: '/*'
});
}
示例2: configure
public configure(consumer: MiddlewaresConsumer) {
consumer
.apply(passport.authenticate('jwt', { session: false }))
.forRoutes(
{ path: '/media', method: RequestMethod.POST },
{ path: '/media/*', method: RequestMethod.DELETE },
{ path: '/media/*', method: RequestMethod.PUT },
{ path: '/mixes', method: RequestMethod.POST },
{ path: '/mixes/*', method: RequestMethod.DELETE },
{ path: '/mixes/*', method: RequestMethod.PUT },
{ path: '/transcripts', method: RequestMethod.POST },
{ path: '/transcripts/*', method: RequestMethod.DELETE },
{ path: '/transcripts/*', method: RequestMethod.PUT },
{ path: '/accounts', method: RequestMethod.POST },
{ path: '/accounts/*', method: RequestMethod.DELETE },
{ path: '/accounts/*', method: RequestMethod.PUT },
);
}
示例3: configure
configure(consumer: MiddlewaresConsumer) {
consumer.apply(AuthMiddleware)
.forRoutes({
path: '*', method: RequestMethod.ALL
});
}
示例4: configure
configure(consumer: MiddlewaresConsumer): void {
consumer.apply(ResponseMiddleware).forRoutes(
{ path: '*', method: RequestMethod.ALL } // Create application level middleware
);
}
示例5: configure
//全域middleware
public configure(consumber: MiddlewaresConsumer) {
//apply、forRoute方法允許傳入多個參數
consumber.apply(passport.authenticate('jwt', { session: false }))
.forRoutes({ path: '/users', method: RequestMethod.ALL });
}