1

我正在使用Next.js (npm run dev)在组织的代理下处理项目

使用axios处理请求

客户端的所有请求都运行良好,但在 getStaticProps axios 请求函数中出现错误

“在建立安全 TLS 连接之前,客户端网络套接字已断开”

获取静态道具

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 上测试)一切正常

我已经尝试过但没有帮助:

  1. 添加NODE_TLS_REJECT_UNAUTHORIZED=0.env.local

  2. 试图在 axios 配置中设置它

    {
    httpsAgent:
      new https.Agent({
        rejectUnauthorized: false
      });
    }
    
4

0 回答 0