4

I would like to wrap my nodejs application using phonegap. I built my nodejs application using krakenjs and I don't really know which files should go into phonegap.

Nodejs is the server side but it serves all the static files. In my public folder under the krakenjs project I have all the static files (css, imgs, js .. ) but all the html are dustjs template files which the server serves. I am kind of lost. any help would be appreciated.

Thanks!

Biri
  • 189
  • 9
  • You have to search for node.js runtime for iPhone, Android, Windows Phone, ... I'm afraid you have to find a strategy without node.js. I don't know your whole stack, but many JS-libraries can be run in a browser with [browserify](http://browserify.org/). – hgoebl May 16 '14 at 14:40
  • I didn't understand how browserify helps me ? My problem is only with the dust js templates, my nodejs server build and serves me them. My client side code is in regular js files that I can use in phonegap. Maybe I need a dummy index.html file that all he does is request my main page from the server ? what do you think ? – Biri May 16 '14 at 15:45
  • Please explain exactly which pieces of software run where. What do you mean with server-side? Is it a server in the internet? Can you access your server with a browser on your phone and is this working? – hgoebl May 16 '14 at 16:14
  • I am running a nodejs server using krakenjs (It uses express) . I am using dustjs for templating. The nodejs server serves me the pages, it fills the templates with data and returns them to the client. The server is in the internet and I can access my website from any browser (PC, Tablet and Phone). What I want to do is wrap it as a mobile native application, meaning you won't need to go into the browser and navigate to the website, instead it will be a native app that will do so. Thanks for your help! – Biri May 17 '14 at 07:52
  • Hey, I have a similar situation, except I run the express server locally... I can't go the remote URL route, so how do I get dustjs to work in PhoneGap? – Dois Jun 23 '15 at 07:24

1 Answers1

4

With Phonegap, you have a choice of either starting your application from a file local to your application (e.g. www/index.html) or a remote URL.

This is configured via the <content> tag in your www/config.xml file as such:

<content src="index.html" />

for a local file or

<content src="https://mydomain.com/myroute" />

for a remote URL.

If your application is available to non Phonegap users via a web browser and there is no difference between the Phonegap user experience and the regular browser one, it may be easier to point Phonegap directly to your kraken application's URL. You may also choose to implement different routes for Phonegap.

The reason is that you will only have to update your server template if you need to make a change after your Phonegap application has been pushed to the app store. Changing a file local to your application will require a Phonegap rebuild and redeploy.

Don't forget to specify the <access origin> parameter in your Phonegap configuration, for example:

<access origin="https://mydomain.com" subdomains="true" />

The downside of pointing directly to your server will be that you may have to load cordova.js on all your pages (maybe using conditional loading tricks). (See comment below by grundyoso for a better solution)

Community
  • 1
  • 1
dimdm
  • 1,121
  • 1
  • 9
  • 13
  • 1
    I was able to follow this tip effectively, however I'll point out that I didn't need to load *cordova.js* in all my server-side pages. I simply added the *cordova.js* file to the ios bundle within my Phonegap project file system under Platforms. As seen here: http://cl.ly/image/0L1J3J181z22 – grundyoso Dec 21 '14 at 09:01
  • I just edited the answer to point to your solution. Haven't got to testing it but I agree that it is preferable not to mess with the original web app. – dimdm Dec 31 '14 at 16:10
  • I tried this solution and can't seem to get it to work via Phonegap Build, here is my attempt https://gist.github.com/arvi/b6689b46142affb6689ab1ea47e58035 What build method are you using? Cordova, Phonegap CLI or Phonegap Build? – Woppi Aug 18 '16 at 11:37
  • 1
    @Woppi Could you set up a repository that I could clone to reproduce the error? I'll try to look into it... – dimdm Aug 25 '16 at 15:31
  • @dimdm wow, thanks I appreciate your kindness. I was able to make it work using local, I think it's much easier to trace locally and considering I'm a beginner at this. Here is the experiment I made nodejs + sockets + phonegap build for anyone that'll find themselves in the same situation. https://bitbucket.org/arviio/tuts-socket-io-chat-app :) – Woppi Aug 26 '16 at 07:39