流星“ - 移动设置”被服务器值覆盖? [英] Meteor "--mobile-settings" being overriden by server values?

查看:44
本文介绍了流星“ - 移动设置”被服务器值覆盖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Meteor 移动应用提供一些按构建配置。 - mobile-settings 选项看起来非常适合此任务 - 它允许您在构建时将配置(JSON)传递给移动客户端 - 与 - 设置选项适用于服务器。

I'm trying to provide some per-build configuration for a Meteor mobile app. The --mobile-settings option looked to be ideal for this task - it allows you to pass configuration (JSON) to mobile clients at build time - in the same way that the --settings option does for the server.

然而,我看到一些意想不到的行为......任何事情当客户端从服务器刷新时,通过 - mobile-settings 传递给移动客户端看起来被覆盖。

However, I'm seeing some unexpected behaviour... anything passed to the mobile clients via --mobile-settings looks to be being overridden when the client refreshes from the server.

这就是我做的....

Here's what I did....


  1. 写了一个非常简单的应用程序它从 Meteor.settings.public.blah 中读取设置值并在屏幕上显示。

  2. 将此应用程序部署到流星服务器(不带任何移动设置文件)。

  3. 构建相同的应用程序android,指向上面的服务器并使用 - mobile-settings 选项集 - 指向一个声明'blah'属性的设置文件。将它安装在设备上。

  4. 当我在设备上运行应用程序时,应用程序启动,屏幕正确显示了设置。

  5. 但是几秒钟后,应用程序刷新,设置消失。

  1. Wrote a very simple app which reads a settings value from Meteor.settings.public.blah and displays it on-screen.
  2. Deployed this app to the meteor servers (without any mobile-settings file).
  3. Built the same app for android, pointing to the server above and with the --mobile-settings option set - pointing to a settings file which declared the 'blah' property. Installed it on a device.
  4. When I ran the app on the device, the app started and the screen correctly displayed the blah setting.
  5. However, after a couple of seconds the app refreshed and the setting disappeared.

在刷新时,为什么特定于移动设备的构建时间值是否从服务器覆盖?移动设置文件是否也需要存在于服务器上?

On refresh, why would a mobile-specific, build-time value be overridden from the server? Does the mobile-settings file need to exist on the server too?

提前致谢。

更新

好的,通过下面的讨论,我想我需要澄清我的问题......

Ok, going by a discussion below, I think I need to clarify my question a little...

我上面所描述的是我所看到的行为。但是,我发现这种行为令人困惑,我很难找到有关此功能的任何文档来详细说明预期的行为。

What I've described above is the behaviour I'm seeing. However, I find this behaviour confusing and I'm struggling to find any documentation on this feature to detail what the expected behaviour is.

我能找到的最好的是一个线程其中一个原始开发者评论的内容( https://groups.google .COM /论坛/#!MSG /流星通话/ Jbfnk5kCvW4 / 6qvccun2dQ0J )。他说...

The best I could find was a thread where one of the original devs commented (https://groups.google.com/forum/#!msg/meteor-talk/Jbfnk5kCvW4/6qvccun2dQ0J). He said...


您只需构建两次移动应用程序,并将不同的json传递给 - mobile-settings

这似乎不支持我所看到的行为 - json传递给的地方 - -mobile-settings将被覆盖到服务器的任何内容覆盖。因此我的困惑。

This does not seem to support the behaviour I'm seeing - where the json passed to --mobile-settings would be overwritten by whatever was deployed to the server. Hence my confusion.

如果有人能指出我的任何文件或以任何方式确认这种行为,我将不胜感激。

I would appreciate it if anyone could point me to any documentation or confirm this behaviour either way.

推荐答案

简而言之



让我们来看看

In short

Let's look at

meteor build --help

它显示为:

--mobile-settings   Set optional data for the initial value of Meteor.settings
                    in your mobile application. A new value for
                    Meteor.settings can be set later by the server as part of
                    hot code push.

所以它看起来像你为服务器提供的设置 METEOR_SETTINGS 环境变量始终优先。如果还没有服务器设置,移动设置仅作为后备/默认值。

So it looks like the settings you provide for the server with the METEOR_SETTINGS environment variable always takes precedence. The "mobile settings" are only there as a fallback/defaults values if there are no server setting yet.

但是,可能还不清楚为移动设备设置另一个设置对象的目的是什么。我不是Cordova的专家,但我想这里的问题是应用程序如何被引导。

Still, it may not be clear what's the purpose of having another settings object for a mobile device. I am not an expert on Cordova, but I guess the problem here is how the application gets bootstrapped.

通常,当您从meteor服务器请求初始页面 Meteor.settings 对象 - 当然 - 与您的服务器配置保持同步。这由 webapp 包处理:

Normally, when you request the initial page from meteor server the Meteor.settings object is - of course - up-to-date with your server config. This is taken care of by the webapp package here:

https://github.com/meteor/meteor/blob/devel/packages/webapp/webapp_server.js# L352

请注意,当您在移动设备上安装应用程序时,它会变得有点复杂。当然,安装过程与您的服务器当前状态无关,因此除非在移动构建过程中事先知道,否则无法获取设置的初始值。这是您需要 - mobile-settings 选项的唯一原因。它们不是为了改变您的移动设备设置,而是在热代码推送期间从服务器加载最新设置对象之前提供初始值。

Note that it becomes a bit more complicated when you install the application on your mobile device. Of course the installation process has nothing to do with your server current state, hence there's no way to get the initial values for settings unless they're know in advance during the mobile build process. That's the only reason you need that --mobile-settings option. They're not there to alter your settings for a mobile device but to provide initial values before the up-to-date settings object can be loaded from your server during the hot-code-push.

如果两个设置对象不同,它总是会发生,因为你可以在代码中看到这里计算哈希值时会考虑 PUBLIC_SETTINGS 值,用于判断是否客户代码是最新的。

And it will always happen if the two settings objects are different, because as you can see in the code here the PUBLIC_SETTINGS value is taken into account while computing the hash which is used to tell if the the client code is up-to-date.

所以结论是:你的移动设置 - 或者至少是它的公共部分 - 应该尽可能地反映当前的服务器配置。每次更改公共设置时,您还应重建移动应用程序并发布更新,以确保新客户拥有开箱即用的最新版本设置。

So the conclusion is: your "mobile settings" - or at least the public part of it - should reflect the current server configuration as close as possible. Every time you change your public settings you should also rebuild your mobile application and publish the update to make sure your new customers have the up-to-date version of settings out-of-the-box.

理想情况下,客户端应用程序不应依赖 Meteor.settings 来正确启动。即使对象为空,也应该有一些不会破坏用户体验的默认行为。

Ideally, the client application should not depend on Meteor.settings to startup properly. Even if the object is empty there should be some default behavior that does not break the user experience.

这篇关于流星“ - 移动设置”被服务器值覆盖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆