【问题标题】:Unable to connect to Realm Object Server using NodeJs无法使用 NodeJs 连接到领域对象服务器
【发布时间】:2018-03-23 12:28:51
【问题描述】:

我已经在谷歌云平台上的虚拟机上使用 docker 容器方法安装了 Realm Object Server。容器正在运行,我可以在浏览器中连接并查看 ROS 页面。我可以使用 Realm Studio 连接到它并添加一个用户。

我有一个 nodeJS 应用程序在 Mac 上本地运行,我正在尝试使用它来登录并写入服务器上的领域。当我运行应用程序时出现错误,返回的用户是一个空对象。不知道我做错了什么。 我是 NodeJS 的新手。

代码:

        var theRealm;
    const serverUrl = "http://xx.xx.xx.xx:9080";
    const username = "xxxx";
    const password = "xxxx";

    var token = "long-token-for-enterprise-trial";
    Realm.Sync.setFeatureToken(token);

    console.log("Will log in user");
    Realm.Sync.User.login(serverUrl, username, password)
        .then(user => {
                                                           ``
        // user is logged in
        console.log("user is logged in " + util.inspect(user));
            // do stuff ...
            console.log("Will create config");
            const config = {
                schema:[
                    schema.interventionSchema,
                    schema.reportSchema
                ],
                sync: {
                    user: user,
                    url: serverUrl
                }
            };
            console.log("Will open realm with config: " + config);
            const realm = Realm.open(config)
                .then(realm => {
                    // use the realm instance here
                    console.log("Realm is active " + realm);
                    console.log("Will create Realm");
                    theRealm = new Realm({
                        path:'model/realm_db/theRealm.realm',
                        schema:[
                            schema.interventionSchema,
                            schema.reportSchema
                        ]
                    });
                    console.log("Did create Realm: " + theRealm);
                })
                .catch(error => {
                    // Handle the error here if something went wrong
                    console.log("Error when opening Realm: " + error);
                });
            })
        .catch(error => {
            // an auth error has occurred
            console.log("Error when logging in user: " + error);
        });

输出:

Will log in user
Server is running...
user is logged in {}
Will create config
Will open realm with config: [object Object]
TypeError: Cannot read property 'token_data' of undefined
    at performFetch.then.then (/pathToProject/node_modules/realm/lib/user-methods.js:203:49)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
TypeError: Cannot read property 'token_data' of undefined
    at performFetch.then.then (/pathToProject/node_modules/realm/lib/user-methods.js:203:49)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

错误@user-methods.js:203:49

const tokenData = json.access_token.token_data;

json 是: { 用户令牌: {令牌:'xxxxxxxx', 令牌数据: { app_id: 'io.realm.Auth', 身份:'xxxxxx', 盐:'xxxxxxxx', 过期:1522930743, is_admin: 假 } } };

所以 json.access_token.token_data 是未定义但 json. user_token.token_data 不会。

【问题讨论】:

  • 你的 ROS 版本是多少?
  • 我期望的最新版本,我按照此处的说明在 docker 容器中运行它:realm.io/docs/get-started/enterprise-installation/…
  • 您需要我找到确切的版本号吗?我不确定如何从该容器中找到它。
  • 知道它是 ROS 2.x 还是 ROS 3.x 很重要
  • 很公平。我不确定是简短的答案。在我的本地系统上,我安装了 3.0.0,但我使用 docker 安装的文档没有说明安装了哪个版本的 ROS,我不知道如何找到。

标签: node.js realm realm-object-server


【解决方案1】:

我建议您尝试使用 Realm Studio 的 ROS 连接,因为您也可以检查日志,这将帮助您修复错误。如果您仍然无法修复,那么您可以联系 Realm 支持团队,即使他们帮助我使用 Docker 解决了 Xamarin Forms 中的 ROS 连接问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-02
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多