【问题标题】:Accept self signed certificate on local Apollo's RESTDataSource接受本地 Apollo 的 RESTDataSource 上的自签名证书
【发布时间】:2021-03-30 01:25:54
【问题描述】:

在创建RESTDataSource 类扩展和本地开发时,如何接受自签名本地证书?

【问题讨论】:

    标签: javascript graphql apollo serverless node-fetch


    【解决方案1】:

    Apolloapollo-datasource-rest's RESTDataSource 在其魔术方法的第三个参数中接受节点获取参数(即 this.get())。

    这允许我们在本地接受自签名证书。

    为了能够做到这一点,我们需要利用节点的https 模块,以便我们稍后可以通过代理:

    import https from 'https'
    
    
    const agent = new https.Agent({
      rejectUnauthorized: !process.env.IS_OFFLINE // this will work for serverless-offline but feel free to pass anything that detects you are working locally,
    })
    

    之后我们需要做的就是将代理作为选项传递:

    class dataSourceApiExample extends RESTDataSource {
    
      ...
      
      this.get() {
       'some-endpoint',
       {},
       {
         agent
       }
      }
    
      ...
    }
    
    

    【讨论】:

      猜你喜欢
      • 2019-12-23
      • 2021-05-07
      • 2011-11-26
      • 2015-12-25
      • 2017-04-18
      • 1970-01-01
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      相关资源
      最近更新 更多