Subdomain support for meteor (for example, slack - http://team.slack.com)

support for subdomains in the meteor (for example, with slack - http://team.slack.com )

As in the case of weak applications, users can create their own subdomains (unique), and depending on the subdomain, the data must be downloaded, and the application will continue around this. I can use something like http://slack.com?team=TeamName , but I think the subdomain will be much cleaner and better.

Any suggestions / pointers.

Thank.

+4
source share
1 answer

Taken from the 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. : " ". , .

+11

Source: https://habr.com/ru/post/1598481/


All Articles