title: How to redirect incoming URL requests by adding additional parameters
body: <p>Problem: I get an incoming HTTP request to my server application. The request is something like this : <a href="http://example.com?id=abc" rel="nofollow noreferrer">http://example.com?id=abc</a>. I need to parse this request, patch additional URL parameters and call a hosted html file. So:</p>
  
  <p><a href="http://example.com?id=abc" rel="nofollow noreferrer">http://example.com?id=abc</a> => <a href="http://example.com:8080/temp.html?id=abc&amp;name=cdf" rel="nofollow noreferrer">http://example.com:8080/temp.html?id=abc&amp;name=cdf</a>.</p>
  
  <p>So the client should see temp.html</p>
  
  <p>Here's the code:</p>
  
  <pre><code>function onRequest(request,response) {
  if(request.method =='GET') {
          sys.debug("in get");
          var pathName = url.parse(request.url).pathname;
          sys.debug("Get PathName" + pathName + ":" + request.url);
          var myidArr = request.url.split("=");
          var myid = myidArr[1];
          //Call the redirect function
          redirectUrl(myid);
  }
  http.createServer(onRequest).listen(8888);
  
  function redirectUrl(myid) {
  var temp='';
      var options = {
        host: 'localhost',
        port: 8080,
        path: '/temp.html?id=' + myid + '&amp;name=cdf',
        method: 'GET'
      };
    var req = http.request(options, function(res) {
      console.log('STATUS: ' + res.statusCode);
      console.log('HEADERS: ' + JSON.stringify(res.headers));
      res.setEncoding('utf8');
      res.on('data', function (chunk) {
        temp = temp.concat(chunk);
      });
      res.on('end', function(){
          return temp;
        });
      });
    req.end();
    return temp;
  }
  </code></pre>
  
  <p>Even though this is a really stupid way of going about this issue, I do see the response in the res.end() callback. How to propagate this to the parent calling function onRequest ? </p>
  
  <p>Is there a simpler way of doing this just using node ? I know that there are ways to serve static html files. However, I need to pass URL parameters to temp.html - so I'm not sure how to do this. </p>