证书颁发机构无效

时间:2021-01-07 15:32:07

标签: node.js reactjs express

我正在尝试从我的前端 (reactjs) 向后端 (nodejs/express) 发送 https 请求。

这两个都在本地主机上运行。

后端服务器代码:

const app = require('./app')
const https = require('https');
const fs = require('fs');

const credentials = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};

//connect to the database
require('./db')

const port = 8765;

app.get('/', (req, res) => {
   res.send('Now using https..');
});

var server = https.createServer(credentials, app);

//var server = https.createServer(app);

// listen for requests
server.listen(port, () => {
  console.log("server starting on port : " + port)
});

前端请求:

const {data: Sessions}= await axios.get("https://localhost:8765/...");

使用完全相同的参数执行来自邮递员的此请求会产生所需的结果。但是,当我尝试从前端执行此操作时,我得到: 在 react chrome 扩展中获取 https://localhost:8765/... net::ERR_CERT_AUTHORITY_INVALID

为什么会发生这种情况,我该如何解决?

0 个答案:

没有答案