You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ROOT_URL and DDP_DEFAULT_CONNECTION_URL settings have turned out to be one of the more confusing parts of Meteor, especially when used with mobile clients. They are included in __meteor_runtime_config__ in the generated index.html and take their values based on environment variables or command options.
The main problem is that for mobile clients, subsequent updates delivered through hot code push replace the initially bundled index.html with a freshly generated one. This means the new settings depend on the environment set on the server at that point, and this could disable DDP and hot code push after the first update.
This is confusing, because something that initially worked will suddenly stop working without warning. We autodetect the ROOT_URL with certain commands, but let it default to localhost:<port> with others. (DDP_DEFAULT_CONNECTION_URL has no default for browser clients, but defaults to the value of ROOT_URL for mobile clients.)
For instance, meteor run ios-device or meteor run android-device will correctly set ROOT_URL to an autodetected external IP address. But if you run meteor run ios, meteor run android, or just meteor run, the ROOT_URL will default to localhost. So when a previously working app then reconnects and updates, it will receive a new index.html with the wrong settings and will no longer be able to connect to the server (and will never be able to again, because it won't receive hot code pushes).
This is not just a problem with mobile clients however, although the issues are more serious there. For a browser client, if you connect to the external IP address of a server started with meteor run, ROOT_URL will also default to localhost. That means the value of Meteor.absoluteUrl() will be wrong. You just don't notice it because we use relative URLs to refer to assets, and Meteor.absoluteUrl() isn't used in many other places.
Similarly, DDP_DEFAULT_CONNECTION_URL is not set by default for browser clients, and we then use Meteor._relativeToSiteRootUrl() rather than Meteor.absoluteUrl() to set the URL relative to the site the page was served from. For mobile clients this is not an option, because the URL the page was served from is the local web server. (There are also some known issues with relative DDP URLs that we may want to solve at some point, see comments in client_convenience.js and stream_client_common.js).
The solution is for the server to always be configured with the right external ROOT_URL. Using meteor deploy takes care of setting these values automatically, so there is no need to specify anything in that case. But when deploying on your own server or running in development, you have to make sure to set the ROOT_URL environment variable. This can also be controlled by passing the --server (for run) or --mobile-server (for build) options. (For build, we force you to specify the ROOT_URL when mobile platforms have been added to the project, but for run there is no such requirement.)
I'm not sure what the best way to deal with this is. In order to avoid these problems, it might be better to avoid defaulting to localhost in all cases. The downside of this is that it would also require an active non-local network interface in development. An alternative might be to still allow defaulting to localhost, but not bind to other network interfaces in that case.
The text was updated successfully, but these errors were encountered:
The
ROOT_URL
andDDP_DEFAULT_CONNECTION_URL
settings have turned out to be one of the more confusing parts of Meteor, especially when used with mobile clients. They are included in__meteor_runtime_config__
in the generatedindex.html
and take their values based on environment variables or command options.The main problem is that for mobile clients, subsequent updates delivered through hot code push replace the initially bundled
index.html
with a freshly generated one. This means the new settings depend on the environment set on the server at that point, and this could disable DDP and hot code push after the first update.This is confusing, because something that initially worked will suddenly stop working without warning. We autodetect the
ROOT_URL
with certain commands, but let it default tolocalhost:<port>
with others. (DDP_DEFAULT_CONNECTION_URL
has no default for browser clients, but defaults to the value ofROOT_URL
for mobile clients.)For instance,
meteor run ios-device
ormeteor run android-device
will correctly setROOT_URL
to an autodetected external IP address. But if you runmeteor run ios
,meteor run android
, or justmeteor run
, theROOT_URL
will default tolocalhost
. So when a previously working app then reconnects and updates, it will receive a newindex.html
with the wrong settings and will no longer be able to connect to the server (and will never be able to again, because it won't receive hot code pushes).This is not just a problem with mobile clients however, although the issues are more serious there. For a browser client, if you connect to the external IP address of a server started with
meteor run
,ROOT_URL
will also default tolocalhost
. That means the value ofMeteor.absoluteUrl()
will be wrong. You just don't notice it because we use relative URLs to refer to assets, andMeteor.absoluteUrl()
isn't used in many other places.Similarly,
DDP_DEFAULT_CONNECTION_URL
is not set by default for browser clients, and we then useMeteor._relativeToSiteRootUrl()
rather thanMeteor.absoluteUrl()
to set the URL relative to the site the page was served from. For mobile clients this is not an option, because the URL the page was served from is the local web server. (There are also some known issues with relative DDP URLs that we may want to solve at some point, see comments in client_convenience.js and stream_client_common.js).The solution is for the server to always be configured with the right external
ROOT_URL
. Usingmeteor deploy
takes care of setting these values automatically, so there is no need to specify anything in that case. But when deploying on your own server or running in development, you have to make sure to set theROOT_URL
environment variable. This can also be controlled by passing the--server
(forrun
) or--mobile-server
(forbuild
) options. (Forbuild
, we force you to specify theROOT_URL
when mobile platforms have been added to the project, but forrun
there is no such requirement.)I'm not sure what the best way to deal with this is. In order to avoid these problems, it might be better to avoid defaulting to
localhost
in all cases. The downside of this is that it would also require an active non-local network interface in development. An alternative might be to still allow defaulting tolocalhost
, but not bind to other network interfaces in that case.The text was updated successfully, but these errors were encountered: