【问题标题】:How to guard nestjs swagger endpoint如何保护nestjs swagger端点
【发布时间】:2020-12-29 19:50:04
【问题描述】:

当 swagger 模块设置发生在 main.ts 文件上时,您将如何保护 Nestjs 上的 swagger 文档。

 const options = new DocumentBuilder()
      .setTitle("API")
      .setDescription("NestJS api")
      .setVersion("1.0")
      .build();
    const document = SwaggerModule.createDocument(app, options);
    SwaggerModule.setup("swagger", app, document);

我希望对 swagger docs 端点使用如下所示的保护。

@UseGuards(RolesGuard)

【问题讨论】:

    标签: api authentication swagger nestjs


    【解决方案1】:

    如果你想留在 NestJS 设计中,我建议你使用Interceptors

    或者您可以在应用程序中使用expressfastify 身份验证中间件bootstrap 方法,灵感见this ticket(旧NestJS 版本)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-30
      • 1970-01-01
      • 2022-01-02
      • 2020-09-07
      • 2013-11-28
      • 1970-01-01
      • 1970-01-01
      • 2021-06-23
      相关资源
      最近更新 更多