0

I'm using node.js and the http object to connect to a webserver with a special application server. Works fine for an server at amazon, no problems.

No we have a Classic Loadbalancer running. Works - I can enter the URL of the ELB in my browser and I see the answer of our server.

But when I try to open the same URL using my node.js script I always get an timeout.

Sample code:

try {
  console.log( "start test" );
  var http = require("http");

  var options = { host: "test.server.name",
              port: "80",
             path: "/dp/",
              headers: {
              'Encoding' : 'BINARY'          
              }         
            }; 

  console.log( "start get " + options.host );

  http.get( options , function( res ) {
    console.log( "in callback" );
       
    res.on('data', function(data) {
      console.log( "callback get data " + data );
    });
     
    res.on('end', function() {
      console.log( "callback end" );
    });
        
    res.on('error', function(e) {
      console.log( "callback error" );
    });
  } );
} catch( err ) {
  console.log( "error " + err.message );
}

Code works directly with the server. Doesn't work when using the loadbalancer.

And I have to idea what to do - any ideas?

Klaus Friese
  • 109
  • 1
  • 10
  • The request times out, or you get a response indicating a (408 request or 504 gateway) timeout? – jarmod Feb 25 '19 at 15:26
  • what is the security group of your load balancer ? – Sébastien Stormacq Feb 25 '19 at 15:28
  • @SébastienStormacq - Security group of the loadbalancer is the same as the aws instance and all needed ports are open. – Klaus Friese Feb 26 '19 at 08:50
  • @jarmod - the errormessage is: 'Error: connect ETIMEDOUT 3.120.18.198:80' in _Object.exports._errnoException (util.js:734:11)_ – Klaus Friese Feb 26 '19 at 08:59
  • Additional info: I asked a customer to try this from his machine - different internet connection, different setting (and another country). Same problem. So it's not in my network and/or firewall configuration! – Klaus Friese Feb 26 '19 at 12:33

2 Answers2

0

I got it. Don't know why - but the problem was in the proxy we're using.

I found this: How can I use an http proxy with node.js http.Client? and by using our proxy it worked...

Klaus Friese
  • 109
  • 1
  • 10
0

I found it - it was the proxy.

I set the proxy using this: How can I use an http proxy with node.js http.Client? and this: https://www.vanamco.com/2014/06/24/proxy-requests-in-node-js/

Works now!

Klaus Friese
  • 109
  • 1
  • 10