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

后端 未结 1 587
栀梦
栀梦 2021-02-03 15:30

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 th

1条回答
  •  时光说笑
    2021-02-03 16:01

    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.

    0 讨论(0)
提交回复
热议问题