1

I'm using nodejs with node-http-proxy along with harmon. I am using harmon to rewrite the proxied response to include a javascript file and a css file. When I set the target of the proxy to be http://nodejs.org or anything other than localhost, I receive a 301 or 302 redirect. The script is rewriting the 301 response instead of the fully proxied response. How can I use harmon to rewrite the end response instead of the 302 response?

Here is the example of the script I am running from the harmon example folder:

var http = require('http');
var connect = require('connect');
var httpProxy = require('http-proxy');

var selects = [];
var simpleselect = {};

//<img id="logo" src="/images/logo.svg" alt="node.js">
simpleselect.query = 'img';
simpleselect.func = function (node) {

//Create a read/write stream wit the outer option 
//so we get the full tag and we can replace it
var stm = node.createStream({ "outer" : true });

//variable to hold all the info from the data events
var tag = '';

//collect all the data in the stream
stm.on('data', function(data) {
   tag += data;
});

//When the read side of the stream has ended..
stm.on('end', function() {

  //Print out the tag you can also parse it or regex if you want
  process.stdout.write('tag:   ' + tag + '\n');
  process.stdout.write('end:   ' + node.name + '\n');

  //Now on the write side of the stream write some data using .end()
  //N.B. if end isn't called it will just hang.  
  stm.end('<img id="logo" src="http://i.imgur.com/LKShxfc.gif"         alt="node.js">');      

  });     
 }

  selects.push(simpleselect);

 //
 // Basic Connect App
 //
 var app = connect();

 var proxy = httpProxy.createProxyServer({
   target: 'http://nodejs.org'
 })


 app.use(require('../')([], selects, true));

 app.use(
   function (req, res) {
    proxy.web(req, res);
   }
 );

1 Answers1

0

The problem is that a lot of sites are now redirecting HTTP to HTTPS. nodejs.org is one of those.

I have updated the sample https://github.com/No9/harmon/blob/master/examples/doge.js to show how the http-proxy needs to be configured to deal with HTTPS.

If you still have problems with other arbitrary redirects please log an issue on harmon.

Thanks

Number 9
  • 615
  • 3
  • 9