Wednesday 24 May 2017

Node http-proxy: forward traffic to external https site - crashes

I want to transfer REST requests from my front end wepp app to the API on a external Jira server.

For this I'm using node http-proxy, which has been ok for a Jira server that is http.

But now I want to create a separate server for https.

So making som changes to this example I now have this:

var path  = require('path'),
    fs    = require('fs'),
    httpProxy = require('http-proxy'),
    certFolder = '/my/cert/folder';

//
// Create the HTTPS proxy server listening on port 8002
//
httpProxy.createServer({

  //(placeholder address)
  target: {
    host: 'https://ext.jiraserver.com',
    port: 443
  },

  // letsencrypt cert
  ssl: {
    key: fs.readFileSync(path.join(certFolder, 'privkey.pem'), 'utf8'),
    cert: fs.readFileSync(path.join(certFolder, 'fullchain.pem'), 'utf8')
  },

  secure: true
}).listen(8002);

console.log('https proxy server started  on port  8002');

But when I make a request to my server, https://my.domain.com:8002 it crashes the server with error message:

.../node_modules/http-proxy/lib/http-proxy/index.js:119 throw err; ^

Error: getaddrinfo ENOTFOUND https://ext.jiraserver.com https://ext.jiraserver.com:443 at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

I can't seem to get it to work... The server is online and the address is correct, so I don't know what's wrong.

Is it my code that's wrong or what can I do to get this to work?

Thanks!



via mottosson

No comments:

Post a Comment