10

This is an extension of a question I asked here, which went unanswered. I am attempting to use the Meteor app on my iPad that I'm hosting on my own remote server. The issue is that when I run the following command, the app builds successfully:

sudo meteor run ios-device --mobile-server=XXXX:XXXX

The problem begins when I click the build button in Xcode to deploy the app to my device. It seems to build everything OK and even load the data from my remote server. But after a few seconds, it reverts back to a local database/build. When I check the Xcode log, it says "Finished load of http://meteor.local/" so it seems to be overwriting the remote data with new, local data. I'm not sure if I have something enabled that's causing Xcode to load a local database or if there's something that I have to turn off to prevent it from loading.

UPDATE:

I've resolved the issue using the suggestion from Jey DWork to apply the missing environment variables in the Meteor server startup.

The ones I added were:

Meteor.absoluteUrl.defaultOptions.rootUrl
process.env.ROOT_URL
process.env.MOBILE_ROOT_URL 
process.env.MOBILE_DDP_URL

Without setting these, the ROOT_URL seemed to be getting overwritten after the initial load. As these environment variables do not seem to be documented, I'm still going to search and see if there is a different solution to this issue (as it seems strange that the app would have to re-load itself multiple times before it's usable). For now though, this is a temporary solution.

Community
  • 1
  • 1
Kyle Bachan
  • 1,053
  • 2
  • 15
  • 33
  • 1
    Also I'm not using Xcode and am building for Android your problem (using local data instead of remote data after a few seconds) sound very familiar to an issue I'm currently having, too (http://stackoverflow.com/q/28889748/2543628). Can you check if the ROOT_URL does change in your case with something like `Meteor.startup(function(){ console.log(__meteor_runtime_config__.ROOT_URL); })`? And if it changes what's the value before and after and in that case maybe the problem isn't Xcode related at all. – Jey DWork Mar 09 '15 at 19:56
  • Setting the ROOT_URL variable doesn't make any change. It seems to be getting the right information on load, but then calling meteor.local in the middle of the process that calls the assets. – Kyle Bachan Mar 09 '15 at 20:53
  • 1
    I just found out that there are more variables which store the root URL and the Meteor server is using `process.env.MOBILE_DDP_URL` and `process.env.MOBILE_ROOT_URL` when a Cordova client is connecting and is also publishing those to the clients and triggering a reconnect there. Setting those variables to my real URL in a `Meteor.startup()` function server side resolved my issue here http://stackoverflow.com/q/28889748/2543628 . Maybe you should give that a try, too. At least it shouldn't hurt... – Jey DWork Mar 10 '15 at 00:59
  • That's a great find, dunno why it's not documented.. unfortunately, it didn't seem to solve my problem. Would you be able to post the command you're using to launch the mobile server? One thing I noticed was that if I launch my app in linux, it says "App running at: custom IP address" but when I launch it on iOS (where I'm trying to get the iPad version working), it says "App running at localhost:3000"). The app's are exactly the same, so I'm not sure where the discrepancy is coming from.... – Kyle Bachan Mar 10 '15 at 15:25
  • Also, are you including the port number in the environment variables at all? – Kyle Bachan Mar 10 '15 at 16:25
  • 1
    My procedure is similar to this: 1) Start the server with `ROOT_URL="http://10.0.2.10:3000" meteor --port 3000`; 2) Now I set `Meteor.absoluteUrl.defaultOptions.rootUrl`, `process.env.ROOT_URL`, `process.env.MOBILE_ROOT_URL` and `process.env.MOBILE_DDP_URL` to my `ROOT_URL` manually server side in a `Meteor.startup()` 3) And finally I run `meteor run android-device --mobile-server http://10.0.2.10:3000/`, note that I do this on a local PC which is in sync with the server because my phone has no USB connection to the server. That's working for me now... – Jey DWork Mar 10 '15 at 16:51
  • That did it! I was missing Meteor.absoluteUrl.defaultOptions.rootUrl so I assume that was the culprit... it works alright now though. I'm going to a meteor deployment meet-up in a month so will see if there are any alternate solutions to this. Seems a bit strange that it reloads the app a few times before it's usable. I'll update here if I learn anything. – Kyle Bachan Mar 10 '15 at 18:24
  • I tried your solution but it still fail : # server/main.js Meteor.startup(() => { let server_url = "http://myServer:port"; Meteor.absoluteUrl.defaultOptions.rootUrl = server_url; process.env.ROOT_URL = server_url; process.env.DDP_URL = server_url; process.env.MOBILE_ROOT_URL = server_url; }); – Rebolon Jan 07 '16 at 16:16
  • I've understood my problem, maybe your problem is the same, all explanations here : http://stackoverflow.com/questions/34658956/meteorjs-mobile-build-rooturl-is-always-10-0-2-23000-instead-of-the-real-serv/34792259#34792259 – Rebolon Jan 14 '16 at 14:40

1 Answers1

0

Have a look at this post :

I've understood my problem, maybe your problem is the same, all explanations here : stackoverflow.com/questions/34658956/

  • Your app for smartphone must be built with --server=http://IP:PORT parameters
  • And
  • Your app for server must be started with --mobile-server http://IP:PORT parameters
Rebolon
  • 1,257
  • 11
  • 29