本文整理匯總了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 });
}