【问题标题】:Connecting two Meteor 1.3 applications using DDP使用 DDP 连接两个 Meteor 1.3 应用程序
【发布时间】:2016-06-14 15:57:31
【问题描述】:

我有两个应用程序:siteadmin。我需要admin 使用 DDP 订阅sites 出版物之一。我找不到任何关于此的最新文章或问题,并且没有任何效果。我几乎删除了所有针对 XSS 的保护措施,但没有成功。这是我的代码:

site/server/startup.js

BrowserPolicy.content.allowSameOriginForAll("*");
BrowserPolicy.content.allowDataUrlForAll("*");
BrowserPolicy.content.allowOriginForAll("*");

site/server/publications.js

Meteor.publish('asdf', function(){
    var self = this;
    self.added( "asdf", 'asdfasdfasdflLO', {"TEST","DATA"} );
    self.added('gallery', new Mongo.ObjectID("572b9503d338f74c4700bbbb"), {
        "uuid" : "566caf28-da7b-45d7-ad4a-523aba983cb3",
        "name" : "TEST GALLERY",
        "description" : "THIS IS A TEST",
        "order" : 0,
        "id" : 1
    });
    console.log("SUBSCRIPTION READY");

    self.ready();
    self.onStop(function(){console.log("SUBSCRIPTION STOPPED");
    })
});

admin/server/startup.js

BrowserPolicy.content.allowSameOriginForAll("*");
BrowserPolicy.content.allowDataUrlForAll("*");
BrowserPolicy.content.allowOriginForAll("*");

admin/lib/...../connections.js

import { DDP } from 'meteor/ddp-client' // behaves identically with or without this line

 SiteConnection = DDP.connect(Meteor.settings.public.site.rootUrl);

admin/client/……./page.js

Template.page.onCreated(function(){
    console.log("created");

    FromSite = new Meteor.Collection();

    SiteConnection.subscribe('asdf', function() {
        console.log('Data list starts here:');
        FromSite.find().forEach(function(data){console.log(data)});
        Galleries.find().forEach(function(data){console.log(data)});
    });
});

当访问管理页面时,site 记录 SUBSCRIPTION READY 但从不发送任何数据。

另一方面,当site 订阅asdf 本身时,我的 DDP 记录器会生成以下浏览器控制台输出:

考虑到这一点,我们知道:

  • 出版作品
  • 我们正在连接到正确的 URL

为什么admin 没有得到任何数据?提前致谢

* 更新 *

来自siteadmin 的标题:

$curl -I https://www.site-local.com/
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Mon, 09 May 2016 20:17:18 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
vary: Accept-Encoding
x-content-type-options: nosniff
access-control-allow-origin: *
x-frame-options: SAMEORIGIN
content-security-policy: default-src 'self' data: http://* https://*; script-src 'self' 'unsafe-inline' data: http://* https://*; connect-src * 'self' data: http://* https://*; img-src data: 'self' http://* https://*; style-src 'self' 'unsafe-inline' data: http://* https://*;

大家可以在这里seeconnect-src * 'self',该应用程序可以通过 websockets 与任何域连接。希望这有助于缩小问题的范围。

【问题讨论】:

    标签: javascript node.js meteor cross-domain ddp


    【解决方案1】:
    FromSite = new Meteor.Collection();
    

    此行没有定义集合或集合相关的连接。虽然看起来你也有点混淆了情况。这里没有跨站点数据传输。 这甚至不需要:

    SiteConnection = DDP.connect(Meteor.settings.public.site.rootUrl);
    

    问题是您在客户端的流星集合没有描述它所指的集合 - 您需要的是:

    Template.page.onCreated(function(){
        console.log("created");
    
        FromSite = new Meteor.Collection('asdf');
    
        Meteor.subscribe('asdf', function() {
            console.log('Data list starts here:');
            FromSite.find().forEach(function(data){console.log(data)});
            Galleries.find().forEach(function(data){console.log(data)});
        });
    });
    

    注意第 4 行和第 6 行的变化

    如果我没记错的话,SiteConnection 似乎只是与默认 Meteor 服务器建立第二个连接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 2017-08-02
      • 1970-01-01
      • 2016-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多