import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'; // import * as cors from 'cors'; import { AuthMiddleware } from 'src/middleware/auth.middleware'; import { CSRFMiddleware } from 'src/middleware/csrf.middleware'; import { UserMiddleware } from 'src/middleware/user.middleware'; import { ValidateCSRFMiddleware } from 'src/middleware/validate-csrf.middleware'; import { OAuth2Module } from 'src/modules/oauth2/oauth2.module'; import { OAuth2Service } from 'src/modules/oauth2/oauth2.service'; import { UserModule } from 'src/modules/objects/user/user.module'; import { OAuth2Controller } from './oauth2-router.controller'; @Module({ controllers: [OAuth2Controller], imports: [OAuth2Module, UserModule], }) export class OAuth2RouterModule implements NestModule { // private corsOpts = cors({ origin: true, credentials: true }); constructor(private _service: OAuth2Service) {} configure(consumer: MiddlewareConsumer) { consumer .apply( CSRFMiddleware, UserMiddleware, AuthMiddleware, ValidateCSRFMiddleware, ) .forRoutes('oauth2/authorize'); // consumer // .apply(this.corsOpts) // .forRoutes('oauth2/token', 'oauth2/introspect', 'oauth2/user'); consumer.apply(this._service.oauth.express()).forRoutes(OAuth2Controller); } }