Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

node.js - Certifiction error from chrome browser using ReactJS

i am trying to send an https request from my frontend (reactjs) to backend (nodejs/express).

These two both run in localhost.

Back end server code:

    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)
    });

front end request:

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

i am trying to send an https request from my frontend (reactjs) to backend (nodejs/express).

These two both run in localhost.

Back end server code:

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)
});

front end request:

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

doing this request from postman with the exact same parameters produces the desired result.However when i try to do this from frontend i get: GET https://localhost:8765/... net::ERR_CERT_AUTHORITY_INVALID in react chrome extention.I believe this is because i am using a self signed certificate and chrome browser can't verify it's validity.

Is there a way to temporarily disable this verification step from chrome?

If not how else can i solve this?

Not : Doing this with HTTP works fine but i need it to be HTTPS.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...