How to create a proxy to redirect http requests to https using node.js?

Hi Guys,

I am new to a Node.js developer. I want to create a proxy server that redirects http requests to https. lets say my system IP is xxx.xxx.xxx.xxx:port1 (open port ) my public IP is yyy.yy.yyy.yy ( opened port is port2) I have bound my public IP to a test domain.

I am writing a node.js program that redirects http calls to https. I have found http-proxy-middleware npm that has methods to do this.

var express = require('express')
var proxy =  require('http-proxy-middleware');
const fs= require('fs');

var proxyServer = proxy({
  target: 'https://example.com',
  port: port2,
  changeOrigin: true, 
  cert: fs.readFileSync('certificate.crt'),
})

var app = express()

app.use('*',  proxyServer)

app.listen(port1)

require('opn')('https://example.com')

the certificate is in the same dir. a server is running on port1 on my system

Now, this redirects to the https URL but I get this error Your connection is not private. Apparently, SSL certification failed or some other issue.

Please point out what I am doing wrong and what could be a possible solution.

Thanks & Regards
Camillelola

This does not feel like a CI question. While I don’t think such questions are forbidden here, you would probably have more luck on Stack Overflow.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.