node.js - 无法为我的 nodejs/axios 应用程序提供 Let'sEncrypt 的正确根证书
问题描述
截至 2021 年 9 月 30 日,Let'sEncrypt 根证书已过期(请参阅https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021/)。
从那以后,我完全无法让我的 node.js 应用程序工作(它实际上是 VS Code v1.60.2 的打字稿扩展,在 Windows 10 最新版本上运行)。所有 https 调用都因“证书已过期”错误而惨遭失败。
我的代码相当简单(我想......),看起来像这样:
import * as https from 'https';
import * as axios from 'axios';
const agent = new https.Agent({ keepAlive: true });
const requestHeaders = { 'Accept': '*/*',
'Content-Type': 'application/json',
'Connection': 'keep-alive',
'Cookie': '' };
const cs = axios.create({
withCredentials: true,
baseURL: 'https://my.base.url/',
headers: requestHeaders,
httpsAgent: agent,
timeout: 10000
});
const resp = await cs.get('/suburl');
我已经在互联网上漫游了两天寻求解决方案,但没有任何成功。我基本上有:
- 将 node.js 更新到最新版本(16.10.0),据说可以解决 node 的问题
- 将电子更新到最新版本(13.5.1),这也解决了电子的问题
- 将 axios 更新到最新版本(0.22.0) - 不确定这是否有任何用处,但我认为它不会受到伤害。
无济于事。
所以我试图绕过检查
const agent = new https.Agent({ keepAlive: true, rejectUnauthorized: false });
没用,仍然是相同的错误 CERT_HAS_EXPIRED。
还尝试使用此处建议的解决方案直接在调用中提供根证书: Giving Axios LetsEncrypt's New Root Certificate On Old Version Of Node
不,也没有用。尝试自己下载证书并通过读取 .pem 文件直接加载。没运气...
我想我一定错过了一些东西,但我在这里完全不知所措。直到 10 月 1 日,这件事都像魅力一样发挥作用。任何建议都将受到欢迎!
解决方案
推荐阅读
- c++ - D2D1 初始化映像工厂失败
- html - 无法在 Angular 9 上使用 ngmodel 设置默认选择属性
- python - 如何在python中的关键字之后从字符串中提取浮点数
- python - 统计消息的反应并在有一定数量的反应后执行操作
- sql - 仅当相同值的列不存在时,Postgres 才更新列
- c - 笛卡尔坐标系和二维数组
- c# - 只有在 Visual Studio 中进行调试时,手动激活 WPF 窗口才能正常工作
- php - 通过 php 中的标题值获取 HTML 元素
- python - 在 Django 中使用 FontAwesome5
- laravel - 在单选按钮或复选框列表上处理“其他”的最佳方法是什么