Skip to content
Snippets Groups Projects
microservice.middleware.ts 579 B
Newer Older
  • Learn to ignore specific revisions
  • import { Logger, ForbiddenException } from '@nestjs/common';
    
    export function microserviceMiddleware(req, res, next) {
      Logger.log('[-] Untokenise middleware called');
      if (req.headers['x-consumer-groups']) {
        const arr = req.headers['x-consumer-groups'].split(',');
        arr.map(e => e.trim());
        const group = arr.find(e => e === 'microservice');
        if (group === undefined) {
          throw new ForbiddenException('You can\'t access this ressource.');
        } else {
          next();
        }
      } else {
        throw new ForbiddenException('You can\'t access this ressource.');
      }
    }