import { Module , NestModule , MiddlewareConsumer , RequestMethod , } from '@nestjs/common' ; import { NextModule , NextMiddleware , } from '@nestpress/next' ; import { LogicModule } from './logics/logic.module' ; import { RouteModule } from './routes/route.module' ; import { ApiAuthMiddleware , RedirectIfAuthenticatedMiddleware , RedirectIfNotAuthenticatedMiddleware , } from './logics/auth/middlewares' ; @ Module ( { imports : [ NextModule , LogicModule , RouteModule , ] , } ) export class AppModule implements NestModule { public configure ( consumer ) { this . handleApiRoutes ( consumer ) ; this . handleRoutes ( consumer ) ; this . handleAssets ( consumer ) ; } private handleApiRoutes ( consumer ) { consumer . apply ( ApiAuthMiddleware ) . forRoutes ( 'api/admin*' ) ; } private handleRoutes ( consumer ) { consumer . apply ( RedirectIfAuthenticatedMiddleware ) . forRoutes ( { path : 'admin/login' , method : RequestMethod . GET , } ) ; consumer . apply ( RedirectIfNotAuthenticatedMiddleware ) . forRoutes ( { path : 'admin' , method : RequestMethod . GET , } ) ; } private handleAssets ( consumer ) { consumer . apply ( NextMiddleware ) . forRoutes ( { path : '_next*' , method : RequestMethod . GET , } ) ; consumer . apply ( NextMiddleware ) . forRoutes ( { path : 'images/*' , method : RequestMethod . GET , } ) ; consumer . apply ( NextMiddleware ) . forRoutes ( { path : 'favicon.ico' , method : RequestMethod . GET , } ) ; } }