【发布时间】:2021-03-30 01:25:54
【问题描述】:
在创建RESTDataSource 类扩展和本地开发时,如何接受自签名本地证书?
【问题讨论】:
标签: javascript graphql apollo serverless node-fetch
在创建RESTDataSource 类扩展和本地开发时,如何接受自签名本地证书?
【问题讨论】:
标签: javascript graphql apollo serverless node-fetch
Apollo 的 apollo-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
}
}
...
}
【讨论】: