1

I was wondering how can I add requestInterceptor method to Swagger used with Nestjs? I can't find anywhere how this property can be added to SwaggerModule configuration. That's how I setup swagger docs:

SwaggerModule.setup('docs', app, document, options2);

Reason I need to use requestInterceptor is that I need to add custom 'Origin' header to Swagger's "Try it out" curl request. The only way to play with it is this requestInterceptor property.

Anyone met this problem before?

Cheers.

jaycohb
  • 13
  • 4

2 Answers2

1

Your options2 object can receive this method, like:

SwaggerModule.setup('docs', app, document, {
  requestInterceptor: (req) => {
    req.headers['Origin'] = 'your custom value'
    return req
  }
})

try this.

Micael Levi
  • 5,054
  • 2
  • 16
  • 27
1

You need to set swaggerOptions object in setup parameters

Ex, if you want to enable cookies:

  SwaggerModule.setup('swagger', app, document, {
    swaggerOptions: {
      requestInterceptor: (req) => {
        req.credentials = 'include';
        return req;
      },
    },
  });
Alexey Petushkov
  • 2,010
  • 19
  • 19