如何解决在 getStaticProps Next.js 中获取 TLS 错误
我正在组织代理下的项目,使用 Next.js (npm run dev)
使用 axios 处理请求
客户端的所有请求都运行良好,但在 getStaticProps axios 请求函数中出现错误
“在建立安全 TLS 连接之前客户端网络套接字已断开连接”
getStaticProps
export const getStaticProps: GetStaticProps = async (context) => {
try {
const pageContent = await fetcher(API_METHODS.GET_PAGE_CONTENT,{
data: { path: "/" },});
return {
props: { data: pageContent },};
} catch (err) {
console.log(err);
return {
redirect: { destination: "/500" },};
}
};
提取器
export const fetcher = async (
url: string,options: AxiosRequestConfig = {}
) => {
const result = await axios
.request({
method: "post",url: `${API_ENDPOINT}/${url}`,...options,})
.catch((err: any) => {
throw err;
});
return result.data;
};
代理之外(在自己的 PC 上测试)一切正常
我已经尝试过但它没有帮助:
-
将
NODE_TLS_REJECT_UNAUTHORIZED=0
添加到.env.local
-
尝试在 axios 配置中进行设置
{ httpsAgent: new https.Agent({ rejectUnauthorized: false }); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。