微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在本地 Apollo 的 RESTDataSource 上接受自签名证书

如何解决在本地 Apollo 的 RESTDataSource 上接受自签名证书

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

解决方法

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
   }
  }

  ...
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。