简体   繁体   English

CERT_HAS_EXPIRED:使用create-react-app的node.js和https请求

[英]CERT_HAS_EXPIRED: node.js and https request using create-react-app

I'm using create-react-app and axios. 我正在使用create-react-app和axios。 In package.json the proxy is configured in this way: 在package.json中,代理是通过以下方式配置的:

  "proxy": {
    "/api-rc": {
      "target": "https://www.example.com",
      "pathRewrite": {
        "^/api-rc": "/api"
      }
    }

but I get this error: 但是我得到这个错误:

Proxy error: Could not proxy request /api/islogged from localhost:3000 to https://www.example.com.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (CERT_HAS_EXPIRED).

I tried to resolve it in two ways: 我试图通过两种方式解决它:

if(process.env.NODE_ENV === 'development'){    
    process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
}

and

export const get = (url, params) => 
    const agent = new https.Agent({
        rejectUnauthorized: false
    });

    const p = params ? {httpsAgent: agent, params: {...params}} : {};

    return axios.get(url, p)
};

but the error is still there :( 但是错误仍然存​​在:(

I solved my issue in this way 我以这种方式解决了我的问题

"/api-rc": {
  "target": "https://www.reportago.com",
  "changeOrigin": true,
  "secure": false,
  "pathRewrite": {
    "^/api-rc": "/api"
  }
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM