title: Proxy with nodejs
body: <p>I develop an webapp, against an api. As the api is not running on my local system, I need to proxy the request so I dont run in cross domain issues. Is there an easy way to do this so my index.html will send from local and all other GET, POST, PUT, DELETE request go to xyz.net/apiEndPoint.</p>
  
  <p>Edit:</p>
  
  <p>this is my first solution but didnt work</p>
  
  <pre><code>var express = require('express'),
      app = express.createServer(),
      httpProxy = require('http-proxy');
  
  
  app.use(express.bodyParser());
  app.listen(process.env.PORT || 1235);
  
  var proxy = new httpProxy.RoutingProxy();
  
  app.get('/', function(req, res) {
      res.sendfile(__dirname + '/index.html');
  });
  app.get('/js/*', function(req, res) {
      res.sendfile(__dirname + req.url);
  });
  app.get('/css/*', function(req, res) {
      res.sendfile(__dirname + req.url);
  });
  
  app.all('/*', function(req, res) {
      proxy.proxyRequest(req, res, {
          host: 'http://apiUrl',
          port: 80
      });
  
  });
  </code></pre>
  
  <p>It will serve the index, js, css files but dont route the rest to the external api. This is the error message I've got:</p>
  
  <pre><code>An error has occurred: {"stack":"Error: ENOTFOUND, Domain name not found\n    at IOWatcher.callback (dns.js:74:15)","message":"ENOTFOUND, Domain name not found","errno":4,"code":"ENOTFOUND"}
  </code></pre>