【发布时间】:2020-09-20 15:05:42
【问题描述】:
我们有一个 Apollo 服务器,它正在调用一个外部 API(它将 REST API 转换为 GraphQL)。直到几天前,这还运行良好,使用 cross-fetch 调用 API。
周五我们开始收到以下错误(如下)。我已经进行了一些搜索,它似乎与证书有关(例如,参见Error: unable to verify the first certificate in nodejs)。按照这个问题的答案,我尝试使用https://www.npmjs.com/package/ssl-root-cas 并把
require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create();
在我的代码开始时,但这似乎不起作用。
更重要的是,我不清楚自己在做什么。我对证书是什么、它们如何工作有一个一般的概念,但在这种情况下,我不清楚为什么我必须向一个不需要几个的公共 API 提供证书几天前。换句话说,虽然我想解决它,但我也想了解这里发生了什么。
{
"errors": [
{
"message": "request to https://www.someapi.com failed, reason: unable to verify the first certificate",
"locations": [],
"path": [
"someSearch"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"message": "request to https://www.someapi.com failed, reason: unable to verify the first certificate",
"type": "system",
"errno": "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
"code": "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
"stacktrace": [
"FetchError: request to https://www.someapi.com failed, reason: unable to verify the first certificate",
" at ClientRequest.<anonymous> (/Users/abc/Documents/projects/yaa-interface-new/node_modules/node-fetch/lib/index.js:1455:11)",
" at ClientRequest.emit (events.js:210:5)",
" at TLSSocket.socketErrorListener (_http_client.js:406:9)",
" at TLSSocket.emit (events.js:210:5)",
" at emitErrorNT (internal/streams/destroy.js:92:8)",
" at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)",
" at processTicksAndRejections (internal/process/task_queues.js:80:21)"
]
}
}
}
],
"data": {
"someSearch": null
}
}
【问题讨论】:
标签: node.js ssl apollo apollo-server