【问题标题】:How to disable swagger API documentation from production server in hapijs如何在 hapijs 中从生产服务器禁用 swagger API 文档
【发布时间】:2018-08-04 06:32:35
【问题描述】:

我正在为 API 使用 hapijs 和 swagger 插件。我需要在生产服务器上推送我的代码,但我不知道如何在不影响我的 API 功能的情况下禁用 Swagger API 文档 UI。

【问题讨论】:

    标签: node.js migration swagger hapijs production


    【解决方案1】:

    根据documentation,您可以通过在注册期间设置选项来关闭documentationPage。该文档还显示了如何使用选项注册插件。

    const hapiSwaggerOptions = {
        info: {
          title: 'Documentation',
          version: '1.0.0',
          description: 'This is the API'
        },
        documentationPage: process.env.NODE_ENV !== 'production'
      };
    
      await server.register([
        Inert,
        Vision,
        { plugin: HapiSwagger, options: hapiSwaggerOptions }, ...]);
    

    【讨论】:

      猜你喜欢
      • 2021-05-26
      • 2019-07-07
      • 2021-08-09
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2016-02-05
      • 2016-05-01
      • 1970-01-01
      相关资源
      最近更新 更多