Wednesday, 24 May 2017

Node http-proxy gives 400 Bad Request

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: 'ext.jiraserver.com',
    port: 443,
    https: true
  },

  // 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/rest/auth/1/session I get a

400 Bad Request

The plain HTTP request was sent to HTTPS port

nginx

It seems it makes a regular http-call to the https-server. Shouldn't the property https: true fix this?

Thanks!



via mottosson

No comments:

Post a Comment