Self signed certificate

Awesome, thanks for that.

Here’s how I’m solving the problem using the http-proxy package. This will spawn a proxy server that serves your HTTP destination over HTTPS. Full code:

let fs = require('fs');
require('http-proxy').createServer({
  target: {
    host: 'localhost',
    port: 8009
  },
  ssl: {
    key: fs.readFileSync('./key.pem', 'utf8'),
    cert: fs.readFileSync('./cert.pem', 'utf8'),
    passphrase: 'pass'
  }
}).listen(8080);

This will create an HTTPS server at port 8080 which forwards to your HTTP webserver (running at port 8009 in this example). Here’s a one-liner to create the needed certificate (for testing only, of course):

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'

You will be prompted to enter a passphrase. The example uses pass as the passphrase. Afterwards, it will output the needed key.pem and cert.pem files used in the proxy example.

1 Like