我创建了两个流星应用程序。一个(www.myapp.com)用于显示所有作者姓名的列表,第二个用于显示作者的详细信息,作者名称为子域,如“authorname.myapp.com”。
流星怎么可能?
谢谢,
答案 0 :(得分:0)
以下方法已在我的应用中成功使用超过1年。 请记住,下面的代码非常简单,应该用作灵感而不是完整的解决方案。
需要meteorhacks:fast-render
。
我假设每个subdomain
的文档都在集合Sites
中。
subdomain Sites collection document:
a.example.com { domain:'a.example.com }
b.example.com { domain:'b.example.com }
我们的想法是,在收到HTML时,可以在客户端上执行Sites.findOne()
。
Sites = new Mongo.Collection('sites')
FastRender.onAllRoutes( function ( path ) {
if ( /(css|js|html|map)/.test( path ) ) {
return;
}
// find subdomain:
var domain = this.headers.host.split( ":" )[0];
// subscribe to site publication
// if domain is in db then send data with HTML file
this.subscribe('site', domain);
} );
Meteor.publish('site', function(domain){
return Sites.find( { domain : domain } );
})
if(Meteor.client){
// if domain was correct then
// user should receive document of collection `sites`
// together with HTML
var site = Sites.findOne();
// using site you can display subdomain specific content
}
应该对你有所帮助: Meteor/Iron-Router: how to define routes using data from settings.json