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

时间:2018-02-07 19:40:22

标签: javascript node.js express https create-react-app

我正在使用create-react-app和axios。在package.json中,代理以这种方式配置:

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

但是我收到了这个错误:

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).

我试图通过两种方式解决它:

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

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

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

    return axios.get(url, p)
};

但错误仍然存​​在:(

1 个答案:

答案 0 :(得分:0)

我以这种方式解决了我的问题

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