0

I have a project on NodeJs(backend) and Angular9(frontend). I was doing a SignUp. I have this api from the backend(NodeJs) side

             http://localhost:3001/account/login 

and upon implementation the project was running and it moved me from the SignUp page to other pages within the application and it was moving me from the login page to another page inside the application, But I changed the api, instead of http, I put https

         https: // localhost: 3001 / account / login

But the application no longer works. It just displays the SignUp page, and when I enter the data it does not transfer me to other pages. And I have this error that appeared when I Click "Inspect" in Chrome:

        POST https://localhost:3001/account/login 
        net::ERR_CERT_AUTHORITY_INVALID

How Can I Solve This Problem?

dawsnap
  • 994
  • 9
  • 21

1 Answers1

0

I've faced the same problem and I've found a solution here

If you have using the express framework for your rest API, then the following solution work for you
First, you need to create a "cert and key" file using the following command

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./selfsigned.key -out selfsigned.crt

After that please put the below code into your express.js

var fs = require('fs');
var http = require('http');
var https = require('https');
var privateKey  = fs.readFileSync('sslcert/selfsigned.key', 'utf8');
var certificate = fs.readFileSync('sslcert/selfsigned.crt', 'utf8');

var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();

// your express configuration here

var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);

httpServer.listen(8080);
httpsServer.listen(8443);

I've taken a reference from the stack overflow answer