import { Module, NestModule, MiddlewareConsumer, RequestMethod, } from '@nestjs/common'; import { BoysController } from './boys.controller'; import { BoysService } from './boys.service'; import { TypeOrmModule } from '@nestjs/typeorm'; import { Boys } from './entities/boys.entities'; import { MyMiddleware } from '../middle-ware/my_/my_.middleware';
@Module({ imports: [TypeOrmModule.forFeature([Boys])], controllers: [BoysController],
providers: [ { provide: 'boys', useClass: BoysService, },
{ provide: 'boysArr', useValue: ['小龙', '小虎', '小熊'], },
{ provide: 'sayHello', useFactory: () => { console.log('hello nest!'); return 'hello nest!'; }, }, ], })
export class BoysModule implements NestModule { configure(consumer: MiddlewareConsumer) { consumer .apply(MyMiddleware) .forRoutes({ path: 'boys', method: RequestMethod.GET }); } }
|