New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add proxy to support cross-origin requests #51
Comments
Tested and works on:
|
Tested on:
I patched a minor WP8 issue (e6fa4ff) to enable XHRs on local assets. |
hey @mwbrooks , I've tried the new version of phonegap CLI with PhoneGap App Developer + phonegap serve. It seems to use the proxy but the url is wrong, maybe because i'm using https scheme into my jquery ajax call? See the serve logs:
There's a |
I'll look into this! |
Hi @slorber, I'm having trouble recreating your issue. I've tested an Vanilla XHR:
jQuery 1.11.1:
What device platform are you using? Any chance that you could provide a code sample for me? |
Hi @mwbrooks, I'm using some utility class to perform the request:
The client code is:
Note that with Ripple / Nexus 4 AVD it works fine. But with Phonegap App Developer, on my Nexus4, it doesn't work. I use Phonegap CLI 3.4.0-0.19.21 I'm available on IRC as Sebastien-L on french business hours to discuss this if needed and can let you access my |
Have you solved this problem @slorber ?
|
Ok, thanks for info. Maybe little of topic, but if you have time to answer @slorber , do you turn off proxy at Ripple or use local/remote ? If I use local, it's not working, remote I don't have any, so I usually disable proxy and everything works. |
I start chrome with |
I see, thanks for info, much appreciated |
@mwbrooks here are some debug statements. I have added your JQuery call in my code:
I see the log: This still gives me the error. Maybe this state will help you find the problem?
It seems the "domain" is not transmitted very well... I've got exactly the same with JQuery 2.1 or 1.11 and native XHR request like you posted. I suspect the reason you may not see this error is because you do not use the phonegap serve command but rather use some other server like connect, http or express npm modules (like seen in the doc). I guess the originally requested url should have been:
But using 2 slashes in an URL, I don't think it is valid, so it is possible that the http facing layer you are using is normalizing the received url. |
I've tried to modify the proxy.js code to check the url before and after at this point: It appears that the URI is already decoded and already misses a slash before you try to decode it. |
@slorber, I have workaround for testing application at Phonegap developer, I am not sure how does it work with implementing native functions but it serves me pretty well...anyway, instead of listening port 3000, I listen normal 80..you have to run Apache server at local comp, I am using Xampp (wampp).. So in my case I listen 192.168.1.X/folder-of-app/ + I believe you'll have to add www if using phonegap project structure Now, as it is not build over nodejs/ phonegap there is no feedback to the application and shortcuts (3/4 finger touch) refresh or go back are not working, so I suggest to add refresh button somewhere at you screen which will refresh code after you change it. Of course, main thing for me is that ajax cross domain is working like a charm :) If I haven't explain something best, feel free to ask. |
@mwbrooks please also notice that my phone and my phonegap connect servers are not on the same network. I'm using a service called https://github.com/inconshreveable/ngrok This way, anyone from any network can access my served app from any network with a constant url:
I've just tested on the same network, without ngrok and the problem doesn't seem to be here! The
VS
I guess it is an ngrok bug then. When not using ngrok the url logged is correct! |
So in the end the url seems correct, but now I have another bug: the POST request is never transmitted to my local server. Short version:POST with form data of type Here you can find a jsfiddle that use the local proxy launched with The POST request keeps running forever (when it has data only!) Long version:The JS request on the mobile phone is:
The request received by the proxy is: https://gist.github.com/slorber/7902a6ab0bd38aae53f7 The request forwarding doesn't seem to be fired at all.
On my mobile phone, the request seems to keep being running forever. The only logs I see are:
None of the on data/error/end callbacks are fired. A file is created at The file at So it seems the following doesn't work so well:
Because no request gets fired. To demonstrate the problem. I tried to test the proxy manually with curl and a remote service called http://requestb.in/ which permits to receive http requests and log them for introspection.
The last call keeps being pending and no request is logged on http://requestb.in/ I guess this is a bug, maybe from https://github.com/mikeal/request ? @mwbrooks can you please try to use this code in your test, a POST with some data?
|
Sorry @mwbrooks but it doens't seem to solve my problem.
|
Before there was no error (for me), just long nothing until I stopped CLI and then some Proxy error in one line. Was your case same before ? You have invalid URI, "https:/stample.co/authenticateWithoutCookie" -> https:// |
@MrBr yes this is exactly the point! the problem is that it is not me that only put a single slash! @mwbrooks according to my tests this is much better, since I'm able to make my request through my local proxy using both CURL and this JSFiddle http://jsfiddle.net/3wM8c/1/ while it didn't work before. So, for me the problem with connect-phonegap has been fixed, as the proxy seems to work fine. However I am still unable to use the proxy on my mobile with the Phonegap App Developer :( I guess this time it is the mobile app that removes a slash.
Notice that this app works perfectly fine with Ripple, AVD, deployed as dev APK. It is even published on Google Play Store! https://play.google.com/store/apps/details?id=co.stample&hl=en |
I have the mobile app version 1.1.0 and it seems I can't upgrade it through the store so I guess it's the last one |
Closing. Support was added a while back. |
Problem:
The PhoneGap Developer App cannot make cross-origin requests because it is served by
connect-phonegap
.Source:
phonegap/phonegap-app-developer#98
Solution:
One potential solution is to allow the
connect-phonegap
middleware to proxy all external requests. An added bonus is that the only the CLI needs to be updated, rather each each app.The text was updated successfully, but these errors were encountered: