gpt4 book ai didi

node.js - 服务器 : Unable to Get Local Issuer Certificate 上的 Node 获取请求失败

转载 作者:搜寻专家 更新时间:2023-10-31 23:01:16 24 4
gpt4 key购买 nike

~ 我正在使用 Node 10.9.0 和 npm 6.2.0 ~

我正在运行以下应用程序,它允许我通过 httphttps 向同一站点发出请求。

var fetch = require('node-fetch')
const express = require('express')
const app = express()

//-- HTTP --
app.get('/test-no-ssl', function(req, res){
fetch('http://jsonplaceholder.typicode.com/users')
.then(res => res.json())
.then(users => {
res.send(users)
}).catch(function(error) {
res.send(error)
})
})

//-- HTTPS --
app.get('/test-ssl', function(req, res){
fetch('https://jsonplaceholder.typicode.com/users')
.then(res => res.json())
.then(users => {
res.send(users)
}).catch(function(error) {
res.send(error)
})
})

app.listen(3003, () =>
console.log('Listening on port 3003...')
)

这两个在我的本地机器上都运行良好,并返回 Typicode 提供的 JSON 响应。但是当我将它们作为 Node 应用程序部署在我的网络主机 ( FastComet ) 上时,我得到以下结果:

HTTP /test-no-ssl - 按预期返回 JSON

HTTPS /test-ssl - 返回以下错误:

{ 
"message" : "request to https://jsonplaceholder.typicode.com/users failed, reason: unable to get local issuer certificate",
"type" : "system",
"errno" : "UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
"code" : "UNABLE_TO_GET_ISSUER_CERT_LOCALLY"
}

我搜索了这个错误并尝试了一些常用的修复方法,但没有任何帮助。

这些都不起作用:

npm 配置集注册表 http://registry.npmjs.org/

npm set strict-ssl=false

有没有其他人在共享托管服务提供商(支持 Node)上遇到过这个问题并且能够让它工作?也许甚至是使用 FastComet 的人?楼主的支持人员好像也不知道怎么办,所以我很茫然。

最佳答案

尝试使用以下内容:

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0

关于node.js - 服务器 : Unable to Get Local Issuer Certificate 上的 Node 获取请求失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51995925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com