如何在x.myapp.com上动态路由meteor应用程序,其中x是动态的?

如何在x.myapp.com上动态路由meteor应用程序,其中x是动态的?,meteor,routing,subdomain,Meteor,Routing,Subdomain,我已经创建了两个meteor应用程序。一个(www.myapp.com)用于显示所有作者姓名的列表,另一个用于显示作者姓名为子域(如“authorname.myapp.com”)的作者详细信息 流星是怎么可能的 谢谢,下面的方法在我的应用程序中成功使用了一年多。 请记住,下面的代码非常简单,应该用作灵感而不是完整的解决方案 需要流星黑客:快速渲染 我假设每个子域在集合站点中都有自己的文档 subdomain Sites collection document: a.example

我已经创建了两个meteor应用程序。一个(www.myapp.com)用于显示所有作者姓名的列表,另一个用于显示作者姓名为子域(如“authorname.myapp.com”)的作者详细信息

流星是怎么可能的


谢谢,

下面的方法在我的应用程序中成功使用了一年多。 请记住,下面的代码非常简单,应该用作灵感而不是完整的解决方案

需要
流星黑客:快速渲染

我假设每个
子域
在集合
站点
中都有自己的文档

subdomain         Sites collection document:
a.example.com     { domain:'a.example.com }
b.example.com     { domain:'b.example.com }
其思想是,在客户端上执行
Sites.findOne()
将在收到HTML的同时可用

都是/collections.js server/routes.js client/start.js 应该对您有所帮助:

在哪里编写此代码?在我的第一个应用程序还是第二个应用程序中?如果有的话,你能分享一个示例吗?我的方法是只有一个应用程序,其中有许多子域指向它。我的应用程序位于域:app.example.com。然后,每个新用户都有一个子域:X.otherdomain.com。最后一件事是添加DNS条目:X.otherdomain.com CNAME app.example.comYes kuba,我想这样做。但是我的域名应该像www.example.com一样固定,当点击子域名链接时,它应该像我.example.com一样。我怎样才能做到这一点?你也是这样做的。只需添加DNS条目:*.example.com CNAME www.example.com。子域www.example.com应指向您的服务器IP(DNS A条目)
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
   }