Mobile app : app refresh and then the ROOT_URL is not anymore the good one, but http://10.0.2.2.3000

since few days i have some problem with meteorjs and mobile build. The problem occurs with 3 differents apps.

I build the application with np scripting and this kind of script :

#!/usr/bin/env bash

if [ -z "$npm_package_config_mongourl" ]; then echo "No mongourl config found in package.json"; else echo "set mongourl" && export MONGO_URL=$npm_package_config_mongourl; fi
if [ -z "$npm_package_config_mongooplogurl" ]; then echo "No mongooplogurl config found in package.json"; else echo "set mongooplogurl" && export MONGO_OPLOG_URL=$npm_package_config_mongooplogurl; fi
if [ -z "$npm_package_config_mailurl" ]; then echo "No mailurl config found in package.json"; else echo "set mailurl" && export MAIL_URL=$npm_package_config_mailurl; fi
if [ -z "$npm_package_config_rooturl" ]; then echo "No rooturl config found in package.json"; else echo "set rooturl" && export ROOT_URL=$npm_package_config_rooturl; fi
if [ -z "$npm_package_config_packagedirs" ]; then echo "No packagedirs config found in package.json"; else echo "set packagedirs" && export PACKAGE_DIRS=$npm_package_config_packagedirs; fi
if [ -z "$npm_package_config_mobileserver" ]; then echo "No mobile server config found in package.json (mobile app offline)" && export REBOLON_MOBILE_SERVER=""; else echo "set mobile server" && export REBOLON_MOBILE_SERVER=" --server=$npm_package_config_mobileserver"; fi
if [ -z "$npm_package_config_settingsfile" ]; then echo "No settings file found in package.json" && export REBOLON_SETTINGS=""; else echo "set settings" && export REBOLON_SETTINGS="--mobile-settings $npm_package_config_settingsfile"; fi

if [ -z "$npm_package_config_buildfolder" ]; then (
    echo "set a build folder before running the build system!"
    exit 1
); fi

meteor build $npm_package_config_buildfolder $REBOLON_SETTINGS $REBOLON_MOBILE_SERVER $*;

So once all env vars are created the meteor binary call looks like this :

meteor build ../../build/mobile --mobile-settings ./settings.json --server=http://myserver:3000

Then i inject the app into android emulator and i open a chrom remote debugger. Then i run the app inside the emulator and i have strange behaviour :

  • first the app seems to run well and connect to the server
  • few seconds after it looks llike the app is refreshing and then it is connected to http://10.0.2.2:3000 instead of the original server uri

If i look at the debugger i can see that global var meteor_runtime_config.ROOT_URL is not the one set during the build command :

{meteorRelease: "METEOR@1.2.1", PUBLIC_SETTINGS: Object, ROOT_URL: "http://10.0.2.2:3000", ROOT_URL_PATH_PREFIX: "", appId: "1rm26uv1lh7ui31i489b2"…}

The problem happens also with another app, but not few seconds after the startup. In this app it occurs when i use the camera throught the app and after i select the photo then it come back to the app, but the ROOT_URL become http://10.0.2.2:3000 instead of the real server.

And finally with the third app, the problem occurs when i exit the app (or switch to the smartphone home per exemple) and i come back into the app. Then it refresh, and the ROOT_URL is 10.0.2.2:3000.

I don’t have any clue to understand this. Thanks for the help.

Ok i’ve just understood my mistakes. It’s about --server= param for build command, and --mobile-server for run command.
More explanation here : http://stackoverflow.com/questions/34658956/meteorjs-mobile-build-rooturl-is-always-10-0-2-23000-instead-of-the-real-serv/34792259#34792259