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

**URL:** <https://discuss.circleci.com/t/how-to-create-a-proxy-to-redirect-http-requests-to-https-using-node-js/27022>\
**Category:** Programming Languages\
**Tags:** nodejs\
**Created:** [December 7, 2018, 6:15pm UTC](https://discuss.circleci.com/t/how-to-create-a-proxy-to-redirect-http-requests-to-https-using-node-js/27022 "2018-12-07T18:15:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![camillelola](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@camillelola](https://discuss.circleci.com/u/camillelola)\
**Post date:** [December 7, 2018, 6:15pm UTC](https://discuss.circleci.com/t/how-to-create-a-proxy-to-redirect-http-requests-to-https-using-node-js/27022/1 "2018-12-07T18:15:27Z")

</div>

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](https://mindmajix.com/node-js/node-basic-examples) that redirects http calls to https. I have found http-proxy-middleware npm that has methods to do this.

```auto
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

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [December 9, 2018, 3:34pm UTC](https://discuss.circleci.com/t/how-to-create-a-proxy-to-redirect-http-requests-to-https-using-node-js/27022/2 "2018-12-09T15:34:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [April 28, 2019, 7:42am UTC](https://discuss.circleci.com/t/how-to-create-a-proxy-to-redirect-http-requests-to-https-using-node-js/27022/4 "2019-04-28T07:42:20Z")

</div>

Closed on April 28, 2019, 7:42am UTC

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