问题描述
我有一个在本地服务器上运行的Meteor应用程序(,就像我预期的那样。第二次未加载远程内容时,会返回。 / p>
现在的问题是,为什么Meteor / Cordova会这样做,如何阻止这种行为?因为显然我不能用这种方式测试应用程序。我还不确定它是否会在生产中工作,当我有一个FQDN和HTTPS代理,但这是超出了点。
我试图找到10.0.2.2没有在我的局域网运行在那里,我没有指定这个IP在任何地方,并发现在 /cordova-build/www/application/index.html
这似乎是从 boilerplate_web.cordova.html
(请参阅此链接)。但是Meteor提供了用文件夹 cordova-build-override
覆盖这些生成的文件的可能性,因此我删除了整个
if(/Android/i.test(navigator.userAgent)){
// [...]
}
阻止并添加了一个短 console.log('removed')
。这被调用所以我知道重写是成功的,当我grep通过整个构建的.apk文件10.0.2.2不再被发现 - 仍然的行为是一样的。
所以即使你设置了 ROOT_URL
正确地,仍然有一些特殊的变量,它的手机版本没有设置,可能包含 localhost
。并且在meteor项目中似乎存在更多的代码片段,除了 localhost
和 10.0.2.2
当Cordova客户端正在连接时。所以这似乎导致我的应用程序重新连接到10.0.2.2。
我可以找到的移动网址变量是
process.env .MOBILE_ROOT_URL
与
process.env.MOBILE_DDP_URL
。因此,在 Meteor.startup()
函数中,我现在将其设置为服务器端的真实 ROOT_URL
。我的Android(Cordova)应用程序现在仍然是在第一次启动后几秒钟重新连接,但它重新连接到相同(和真实的)服务器URL(因此一切正常)!
我还不知道为什么它的重新连接和那些移动变量和它们的使用似乎没有很好的记录(或我错过了一些东西),但我可以生活的方式的事情现在工作。
I have a Meteor app which runs on a local server for developement (http://10.0.2.10:3000). The ROOT_URL
is set correctly so __meteor_runtime_config__.ROOT_URL
equals this URL. Of course the app is working perfectly fine in the browser on a client computer within 10.0.2.0/24. The app is also working fine on mobile chrome/firefox on my android cell phone which is also part of 10.0.2.0/24. However when I try to run it as app on this cell phone with meteor run android-device --mobile-server http://10.0.2.10:3000/
something strange happens:
When the app starts for the first time (or the first time after I clear all app data) it works like it should (content from the DB is loaded) for a few short seconds. Then the app reloads and any remote content from the DB isn't loaded anymore. I have added the following function to see where Meteor tries to connect to:
Meteor.startup(function(){
console.log(__meteor_runtime_config__.ROOT_URL);
})
The first time when remote content is loaded this returns http://10.0.2.10:3000/ like I would expect. The second time when remote content isn't loaded it returns http://10.0.2.2:3000/.
The question now is, why is Meteor/Cordova doing this and how can I stop this behavior? Because obviously I cannot test the app this way. I'm not yet sure if it would work in production when I have a FQDN and HTTPS proxy but that's beyond the point.
I tried to find 10.0.2.2 as nothing in my LAN is running there and I have not specified this IP anywhere and found it in /cordova-build/www/application/index.html
which seems to be generated from boilerplate_web.cordova.html
(see this link https://searchcode.com/codesearch/view/91819963/). However Meteor offers the possibility to override these generated files with a folder cordova-build-override
and so I did removing the whole
if (/Android/i.test(navigator.userAgent)) {
//[...]
}
block and added a short console.log('removed')
. This gets called so I know the override was successful and when I grep through the whole built .apk file 10.0.2.2 isn't found anymore - still the behavior is the same.
Any ideas what's going on and what to do?
So even when you set your ROOT_URL
correctly there are still special variables for mobile versions of it which do not get set and may contain localhost
. And there seem to exist more code snippets in the meteor project which replace localhost
with 10.0.2.2
aside from the one I mentioned above, when a Cordova client is connecting. So that seems to cause my app to reconnect to 10.0.2.2.
The mobile URL variables I could find areprocess.env.MOBILE_ROOT_URL
andprocess.env.MOBILE_DDP_URL
. So in a Meteor.startup()
function I now set those to my real ROOT_URL
on the server side. My Android (Cordova) app now still is reconnecting a few seconds after its first start up but it's reconnecting to the same (and real) server URL (thus everything works fine)!
I still don't know why its reconnecting and those mobile variables and their use don't seem to be very well documented (or I missed something) but I can live with the way things work now.
这篇关于如何防止Meteor / Cordova应用程序连接到10.0.2.2? (为什么应用程序连接到那里?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!