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

徘徊边缘 提交于 2019-12-20 10:20:52

问题


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

As in slack my app users can create their own subdomains (unique) and depending on the subdomain the data should be loaded, and around this the application would be proceeded. I can use something like http://slack.com?team=TeamName, but i think the subdomain would be much clean and better.

Any suggestions/pointers.

Thanks.


回答1:


Taken from the Meteor forums.


Using a DNS wildcard to point *.example.com to my app server, I have this in the client code:

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" ) );
});

Make sure the currently signed in user has permission to view the teamId publication records. Anybody can tweak their session and say "I belong to this team." You need to make sure they are actually allowed.



来源:https://stackoverflow.com/questions/31488350/subdomain-support-in-meteor-like-with-slack-http-team-slack-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!