meteor 中的子域支持(就像 slack - http://team.slack.com)

subdomain support in meteor (like with slack - http://team.slack.com)

meteor 中的子域支持(就像 slack - http://team.slack.com

就像在 slack 中一样,我的应用程序用户可以创建自己的子域(唯一的),并且根据子域应该加载数据,并且围绕这个应用程序将继续进行。我可以使用 http://slack.com?team=TeamName 之类的东西,但我认为子域会更干净、更好。

任意 suggestions/pointers.

谢谢。

取自 Meteor forums.


使用 DNS 通配符将 *.example.com 指向我的应用程序服务器,我在客户端代码中有这个:

var hostnameArray = document.location.hostname.split( "." );

if ( hostnameArray[1] === "example" && hostnameArray[2] === "com" ) {
  var subdomain = hostnameArray[0];  
}

if ( subdomain ) {
  Meteor.call( "findTeamBySubdomain", subdomain, function (err, res) {
    var teamId = res;
    if ( teamId )
      Session.set( "teamId", teamId ); 
    }
  });
}

Tracker.autorun ( function () {
  Meteor.subscribe( "teamInfo", Session.get( "teamId" ) );
});

确保当前登录的用户有权查看 teamId 发布记录。任何人都可以调整他们的会话并说 "I belong to this team." 你需要确保他们确实被允许。