Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1535

Express JS https api can't be reached

$
0
0

I'm updating a node.js api with Express js from http to https. This is hosted on AWS, and is accessed through its ip address, not a webdomain.

I've followed the Express documentation, and created self-signed certificates using sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./selfsigned.key -out selfsigned.cert

However my application is not able to reach the server using https, whereas it worked with http. These are the errors I get:

  • Application response: Certificate required
  • Postman response: Connection Refused
  • Powershell response: Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

Could the issue be that the certificates are self-signed? My code is below

let fs = require("fs");let https = require('https');const crypto = require('crypto')let express = require('express');let expressRateLimit = require("express-rate-limit");let mysql = require('mysql');let bodyParser = require('body-parser');let winston = require('winston');require('winston-daily-rotate-file');let key = fs.readFileSync('sslcert/selfsigned.key');let cert = fs.readFileSync('sslcert/selfsigned.crt');let credentials = {key: key, cert: cert};let app = express();app.set('trust proxy', '127.0.0.1');app.use(bodyParser.urlencoded({extended: true}));//App configlet httpsServer = https.createServer(credentials, app);let httpsPort = 443;httpsServer.listen(httpsPort, function() {   console.log("Started codeRedeem https REST API on port " + httpsPort);});

Viewing all articles
Browse latest Browse all 1535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>