title: Node Proxy - Proxy a SSL localhost target from a basic http server
body: <p><strong>What I am trying to do:</strong></p>
  
  <p>Proxy a java api that runs on <code>https://127.0.0.1:443/api/</code> along side my UI that runs on non-SSL <a href="http://127.0.0.1:1337/" rel="nofollow noreferrer">http://127.0.0.1:1337/</a> in order to circumnavigate some CORS issues.</p>
  
  <p><strong>My attempt:</strong></p>
  
  <ol>
  <li>Proxy the api at the SSL port 443 to my non-SSL development port of 1338.</li>
  <li>proxy my UI to 1337</li>
  <li>Proxy 1137 to <code>:8080/index.html</code> and proxy 1338 to <code>:8080/api/</code></li>
  <li>Access my app from localhost:8080</li>
  </ol>
  
  <p><strong>My problem:</strong></p>
  
  <p>The UI comes in just fine... but I can not hit the API at <code>:8080/api/httpSession/init</code></p>
  
  <p>Yes, I can still hit the API at <code>https://localhost/api/httpSession/init</code></p>
  
  <p><strong>api.js</strong> - Renders index.html at :1337</p>
  
  <pre><code>var app = express();
  
  app.all('*', function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    next();
  });
  
  var options = {
    changeOrigin: true,
    target: {
        https: true
    }
  };
  
  httpProxy.createServer(443, '127.0.0.1', options).listen(1338);
  </code></pre>
  
  <p><strong>start.js</strong> - Proxies 1337 and 1338 into 8080</p>
  
  <pre><code>// First I start my two servers
  uiServer.start(); // renders index.html at 1337
  apiServer.start(); // 
  
  // I attempt to patch them back into one single non-SSL port.
  app
    .use('/', proxy({target: 'http://localhost:1337/'}))
    .all('/api/*', proxy({target: 'http://localhost:1338/'}))
    .listen(8080, function () {
      console.log('PROXY SERVER listening at http://localhost:%s', 8080);
    });
  </code></pre>