1

Exclude path does not work when I wrap it up into an Azure function. See ClientInfoModule snippet below.

 exclude({ path :'validate', method : RequestMethod.POST })

Even though the validate is specified in the exclude, the middleware is still called for that route.

Am I missing something trivial here ?

I followed the documentation here : https://docs.nestjs.com/middleware#functional-middleware

Here is a top level snippet of my code below.

import { Injectable, NestMiddleware } from '@nestjs/common';
export class AuthMiddleware implements NestMiddleware {
  ...
}

----------

import { MiddlewareConsumer, Module, NestModule, RequestMethod } from '@nestjs/common';

export class ClientInfoModule implements NestModule{
  configure(consumer: MiddlewareConsumer) {
    consumer
    .apply(AuthMiddleware)
    .exclude(
      { path :'validate', method : RequestMethod.POST },
    )
    .forRoutes(ClientController, SomeOtherController);
  }
}

----------

@Controller('validate')
export class ClientController {
    constructor( ) {}

    @Post()
    async validateFingerprint(@Body() clientPayload: ClientPayload): Promise<ApiResponse> 
    {
      ... this should be excluded from the middleware
    }
}
Fabii
  • 3,820
  • 14
  • 51
  • 92
  • For the time being I did the reverse logic, got rid of the exclude and specified only the routes I wanted to apply the middleware to .forRoutes( { path :'email', method : RequestMethod.POST} ) . This approach seems to work. – Fabii Sep 15 '21 at 20:23

0 Answers0