简体   繁体   中英

How to access nodejs server with https requests in mvc core web app?

I am working on a socket.io based chat application which has different client ie android, ios and web. Chat is working correctly in android and iOS apps.

Nodejs server is used as a backend for socket.js communication. Web part is implemented in asp.net mvc core 3.1. I have created self signed certificates by openssl to access nodejs server over https. I have used folowing code

varhttp = require('http');  
var express = require('express');  
var app = express();  
const httpsPort = 1234;  
var https = require('https');  
var fs = require('fs');  
var options = {  
    key: fs.readFileSync('./key.pem', 'utf8'),  
    cert: fs.readFileSync('./server.crt', 'utf8')  
};  

var secureServer = https.createServer(options, app).listen(httpsPort, () => {  
    console.log("listening at port " + httpsPort);  
});  

But the nodejs server is not connecting and different errors are shown

socket.io.js:14 GET https://x.xxx.xx.xx:8083/socket.io/?EIO=3&transport=polling&t=NRU7hkg net::ERR_CERT_AUTHORITY_INVALID

or

certificate is not valid in chrome with following msg

This CA Root certificate is not trusted because it is not in the Trusted Root Certification Authorities store.

How to properly configure nodejs server over https to communicate with client which is a mvc core 3.1 web application without browser security issues/server not found issue?

You have not declared http as variable Try doing this in first line

var http = require('http');

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