/*!
 * Module dependencies.
 */

var request = require('request');

/**
 * Cross-Origin Requests Middleware.
 *
 * Add support for cross-origin resource requests by proxying all of the requests
 * through this route. Each request includes an encoded path that is the original
 * URL.
 *
 * Options:
 *
 *   - `options` {Object} is unused.
 */

module.exports = function(options) {
    return function(req, res, next) {
        if (req.url.indexOf('/__api__/proxy/') === 0 || req.url.indexOf('/proxy/') === 0) {
            var url = decodeURIComponent(req.url.replace('/proxy/', ''));
            var proxy = request(url);

            proxy.on('error', function(error){
                options.emitter.emit('log', 'Proxy error: url: ' + url, error.code);
            });

            req.pipe(proxy);
            proxy.pipe(res);
        }
        else {
            next();
        }
    };
};

@@ -586,24 +586,26 @@
             
+//
 var proxy = 
@@ -617,16 +617,683 @@
 st(url);
+%0A            //DON'T KNOW WHY BUT THIS HAS TO BE DELETED%0A            delete req.headers.host;%0A%0A            var body;%0A%0A            //AS STATED IN REQUEST DOCUMENTATION, body MUST BE STRING OR ARRAY%0A            if(req.headers%5B'content-type'%5D=='application/json') %7B%0A%0A                body=JSON.stringify(req.body);%0A%0A            %7Delse%7B%0A%0A                body = Object.keys(req.body).map(function (k) %7B%0A                    return k + '=' + req.body%5Bk%5D%0A                %7D).join('&');%0A%0A            %7D%0A%0A            var proxy = request(%7B%0A                method: req.method%0A                , uri: url%0A                , body:body%0A                ,headers:req.headers%0A            %7D);
 %0A%0A      

Fix for proxy cross domain problem