J. Doe
J. Doe

Reputation: 467

How fix or disable proxy in phonegap?

When my app do POST request its work. look like

http://192.168.0.165:3000/proxy/http%3A%2F%2Fhomestead.app%2Fapi%2Fv1%2Fuser%2F

But when I do next request with GET that don't work. I think it because phonegap lost what I send in my params. How I can fix it or disable proxy in phonegap?

Upvotes: 3

Views: 2232

Answers (1)

mesompi
mesompi

Reputation: 699

Add this in your index.html file

(function() {
    var xhr = {};
    xhr.open = XMLHttpRequest.prototype.open;

    XMLHttpRequest.prototype.open = function(method, url) {
        console.log(url);
        if(url.indexOf('/proxy/') == 0){
            url = window.decodeURIComponent(url.substr(7));
        }
        xhr.open.apply(this, arguments);
    };
})(window);

If you begin to face the "Access-Control-Allow-Origin" problem use this extension for chrome (modheader) and add a response like this:

Access-Control-Allow-Origin:http://yourip:3000

If you are making multiple requests and wish the session be shared between them then add another response like this:

Access-Control-Allow-Credentials: true

Upvotes: 5

Related Questions