1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| import { Module } from '@nestjs/common'; import AdminBro from 'admin-bro'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { Database, Resource } from '@admin-bro/mongoose'; import { Model } from 'mongoose'; import { getModelToken, MongooseModule } from '@nestjs/mongoose'; import { AdminModule } from '@admin-bro/nestjs'; import { Comment, CommentSchema } from '../comment/comment.schema';
AdminBro.registerAdapter({ Database, Resource });
@Module({ imports: [ MongooseModule.forRoot('mongodb://127.0.0.1/comment'), AdminModule.createAdminAsync({ useFactory: (commentModel: Model<Comment>) => { return { auth: { authenticate: async () => { return Promise.resolve({ email: 'test' } }), cookieName: 'admin_panel', cookiePassword: 'xxx2arfa', }, adminBroOptions: { rootPath: '/admin', resources: [commentModel], }, }; }, inject: [getModelToken(Comment.name)], imports: [ MongooseModule.forFeature([ { name: Comment.name, schema: CommentSchema }, ]), ], }), ], controllers: [AppController], providers: [AppService], }) export class AppModule {}
|