首页 > 解决方案 > 无法为我的 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');

我已经在互联网上漫游了两天寻求解决方案,但没有任何成功。我基本上有:

无济于事。

所以我试图绕过检查 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 日,这件事都像魅力一样发挥作用。任何建议都将受到欢迎!

标签: node.jsvisual-studio-codeaxioslets-encrypt

解决方案


推荐阅读