5

we built a node.js application for desktop and tablet. It's completely web based application. Now I am planning to implement same application as native app in android using Apache cordova.

Under project directory, we have node_modules,public,.... all client side files are in public folder. When I invoke URL in browser, from client side I am making API call to check whether user already logged or not. like this we are making API calls to my server.

As per my understanding,native app is nothing but we are storing all the client side files into device. whenever user open app will load client side files and as per work flow it will make API calls.

Theoretically I understand that much.

where I stuck :

In desktop app , I used to make API calls with URL like /api/web/shared/reject/, here we don't need to mention server address like localhost:8080/api/web/shared/reject/ that everything browser will take care. This same thing how can I make it work in cordova applications.

How cordova will know whether it is localhost or something else...

Regarding this, I Goggled but I didn't find any tutorials.

can anyone suggest me the way.

vasan
  • 2,203
  • 3
  • 18
  • 22
  • Cordova ultimately requires a WebView which itself extends features of a web browser engine. So, if your app works on the browser, chances are high that it will work the same using Cordova without modification. – Ed_Fernando Oct 07 '14 at 07:33
  • @Ed_Fernando my main doubt, how `cordova` will identify my server address. directly I can't use `localhost:8080/api/web/shared/reject/` to make API calls in my `js` files. – vasan Oct 07 '14 at 07:39
  • `that everything browser will take care` - Does this imply you're able to run the app through a browser? If so, are you able to run it from a client-side browser (say, Chrome/Firefox on Android)? – Ed_Fernando Oct 07 '14 at 09:07
  • You can also check this link out : http://stackoverflow.com/questions/5655975/how-can-i-convert-a-multi-file-node-js-app-to-a-single-file – Ed_Fernando Oct 07 '14 at 11:22

1 Answers1

2

Basically, is a concept problem. Node.js is a technology specialised in backend and some of usages like extend some services/functions, etc. When you talk of a localhost:8080 you are talking that your node.js implementation should be in a server (Amazon, Azure, your own server, nodejitsu, etc), and the public pages or the pages that the client should consume will be added into phonegap, specifically in your www directory and the references for localhost:8080 should be changed for your server (Amazon, your own server, nodejitsu, etc), and the files on your www directory could have references (via GET or POST to retrieve the data from the server. Remember, the Crossdomain problem doesn't happens on phonegap (maybe in a local enviroment should occur). And Phonegap is a framework to develop front-end with HTML5, jquery, CSS3 and other releated technologies. For your specific case the node_modules should be installed in the server too, not on the phonegap project.

Benjamin RD
  • 11,516
  • 14
  • 87
  • 157
  • I added only client side files(public/) into `phonegap`. Their is no `node_module` folder into `phonegap`. If I make API call with production domain, working fine(`http://xxxx.xxxx.xom/usr/api/status`). same thing I tried with `localhost` it's not working(`http://localhost:3005/usr/api/status`) this was the problem. – vasan Oct 07 '14 at 16:29
  • paste the log error, and try do a a `curl` to check if the connectivity is ok (from your pc) or with a ssh or curl from your device – Benjamin RD Oct 07 '14 at 17:12