Search code examples
jquerymobilecordovajquery-mobilemobile-website

Managing service urls in mobile (phonegap) apps


I wrote a phonegap / jQuery mobile app which runs fun in the iphone emulator. My app is getting data from a remote host. At the moment I have ajax requests to "localhost:8080" across my code.

I know, this is not good. I would like to change it.

What is the best practice for URLs in mobile webapps?

I mean, can I differ somehow on "build time" which url to use? Should i do something like "if emu the use localhost"?

Thanks in advance, Christian


Solution

  • I recently deployed a mobile web app which makes various calls to a remote host. For me, the simplest solution was to use relative URIs for all the remote calls I was making, and employ a local reverse-proxy to direct the request to the appropriate server (I was targetting different servers in development vs. production).

    I developed and tested this app locally, using the built-in Apache server in OS X, so configuring this was easy (for local web previews in OS X you modify the <USER_NAME>.conf file found in /etc/apache2/users).

    YMMV, but this was a no-brainer for me in that no code needed to be modified.