在进行服务器端渲染时出现以下错误。
RENDERING ERROR: { [Error: Network error: request to https://api-dev.xyz.io/graphql failed, reason: Hostname/IP doesn't match certificate's altnames: "Host: localhost. is not in the cert's altnames: DNS:*.xyz.io"]
graphQLErrors: null,
networkError:
{ [FetchError: request to https://api-dev.xyz.io/graphql failed, reason: Hostname/IP doesn't match certificate's altnames: "Host: localhost. is not in the cert's altnames: DNS:*.xyz.io"]
name: 'FetchError',
message: 'request to https://api-dev.xyz.io/graphql failed, reason: Hostname/IP doesn\'t match certificate\'s altnames: "Host: localhost. is not in the cert\'s altnames: DNS:*.xyz.io"',
type: 'system',
errno: undefined,
code: undefined },
message: 'Network error: request to https://api-dev.xyz.io/graphql failed, reason: Hostname/IP doesn\'t match certificate\'s altnames: "Host: localhost. is not in the cert\'s altnames: DNS:*.xyz.io"',
extraInfo: undefined }
注意:-我正在使用 react、redux、apollo-client(GraphQL) 和 ExpressJS(NodeJS)。我向其发出请求的 API 服务器位于另一个域中,我无法对其进行任何更改。
在使用客户端渲染时,我没有遇到任何困难,一切都按预期工作,但是在进行服务器端渲染时,我遇到了上述错误。
所以我在我的服务器上尝试了以下方法,但仍然没有运气。
添加自签名证书
在 https 选项中添加 'rejectUnauthorized':false。
const options = { 'key': key, 'cert': cert, 'ca': [ fs.readFileSync('local-certificate.pem') ], 'rejectUnauthorized':false }; https.createServer(options, app).listen(httpsPort, '0.0.0.0', function onStart(err) { if (err) { console.log(err); } console.info('==> Listening on httpsPort %s. Open up http://0.0.0.0:%s/ in your browser.', httpsPort, options); });
有没有办法绕过证书验证,以便我的快速服务器可以向另一个域上具有有效证书的 API 服务器发出请求?
我仍然有点不确定是否可以通过在我的最后(在我的快速服务器上)进行任何更改来修复它。
请让我知道这方面的任何见解。