Multitenancy and Meteor

This is an old topic, but I just wanted to chime in that I had been tinkering with this myself and found working with sub-domains is possible. I use nginx to front-end a single meteor project with a wildcard letsencrypt SSL certificate. My example app uses https://*.domain.devel.buzzledom.com and the underlying logic determines which domain I am trying to access and serves data accordingly.

I also use accounts:password, which means accounts are the same across sub-domains. By passing the localStorage.getItem('Meteor.loginToken') across sub-domains, I can authenticate via Accounts.loginWithToken(loginToken).

Also worth mentioning is that I figured out how to serve the proper favicon.ico per sub-domain from the filesystem, by virtue of the most powerful WebApp.connectHandlers. The static HTML simply points the the URL for favicon that is being handled by the server

  <link rel="icon" sizes="16x16 32x32" href="/favicon/ico?v=2">

and on the server I have this code that looks up the countries flag in /private/flags/ and servers the proper flag favico if it exists

WebApp.connectHandlers.use('/favicon/ico', (req, res, next) => {
  res.writeHead(200, {
    'Content-Type': 'image/x-icon',
  });
  const domain = req.headers.host.split('.').reverse().pop();
  var country = countryList.getName(domain);
  if(country != undefined) {
    country = country.replace(/ /g,'-');
    if (country in COUNTRY_NAME_MAP) country = COUNTRY_NAME_MAP[country];
    try {
      const ico = Assets.getBinary(`ico/${country}.ico`);
      res.end(ico, 'utf8');
    } catch (err) {
      console.log(`error ${err.message}`);
      res.end(Assets.getBinary('flags/unknown.ico'), 'utf8');
    }
  } else {
    res.end(Assets.getBinary('flags/unknown.ico'), 'utf8');
  }
});
8 Likes