【发布时间】:2016-06-14 15:57:31
【问题描述】:
我有两个应用程序:site 和 admin。我需要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 没有得到任何数据?提前致谢
* 更新 *
来自site 和admin 的标题:
$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://*;
大家可以在这里see:
connect-src * 'self',该应用程序可以通过 websockets 与任何域连接。希望这有助于缩小问题的范围。
【问题讨论】:
标签: javascript node.js meteor cross-domain ddp