简体   繁体   中英

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

I'm using create-react-app and axios. In package.json the proxy is configured in this way:

  "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"
  }
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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