title: Node.js+express proxy ssl
body: <p>I'm trying to write a reverse proxy in node.js using express, and it works fine for http requests. The problem is that when requesting https it never responds, and the browser states that the proxy refused to connect. 
  Here is the working code for http requests:</p>
  
  <pre><code>var   app = express(),
        http=require('http');
  
  app.configure(function(){ /* express stuff to log and use routes and the like */ });
  
  http.createServer(app).listen(8000, function(){
    console.log("Express server listening on port " + 8000);
  });
  
  app.all('*', proxy);
  var request=require('request');
  
  var proxy=function(req,resp){
      var data={
          url:req.url,
          headers: {
              'Connection': 'keep-alive'
          }
      }
      var proxy=request(req.url);
      proxy.pipe(resp);
  }
  </code></pre>
  
  <p>Now, as for SSL, i am currently trying with:</p>
  
  <pre><code>var https=require('https'),
      fs=require('fs');
  
  https.createServer({
          key: fs.readFileSync(__dirname+'/ssl/server.key', 'utf8'),
          cert: fs.readFileSync(__dirname+'/ssl/server.crt', 'utf8')
        },app).listen(8001, function(){
    console.log("Express server listening on port " + 8001);
  });
  </code></pre>
  
  <p>The proxy can be used from anywhere requiring <code>50.56.195.215:8000</code> for HTTP and <code>50.56.195.215:8001</code> for SSL. It has no security whasoever, so don't log in to anything important =D</p>
  
  <p>I'm using a self signed SSL Certificate, and i guess it's kind of silly of me to try to do such a thing, but i don't have any ideas left :P</p>