Using Meteor with multiple domains

I’m using multiple domains for my single Meteor application. Now I need to generate individual sitemaps for each of this domains, I’m using here gadicohen:sitemaps

This is how I generate my sitemap:

sitemaps.add('/sitemap.xml', function() {

    var infos = [];
    Infos.find().forEach((doc) => {
        infos.push({page:doc.genURL(), lastmod:doc.createdAt});

    return questions;

The sitemap package uses ROOT_URL as standar domain name, but I need the domain name of the current request to change the config to

sitemaps.config(‘rootUrl’, currentRequestDomain)

Is this possible with Meteor? I know that there is a header package which make it work within a method, but here I need to set it outside of a method.

I think the best way to achieve this would be by changing one line in the gadicohen:sitemaps library. You would just need to change line 67 of the sitemaps.js file from:

pages = pages();


pages = pages(req);

I’d suggest opening a PR with this change (or cloning the package and making the change in your local code). Once this is in place the incoming request will then be available in the sitemaps.add function, and you can use it to toggle your URLs dynamically. For example:

  sitemaps.add('/sitemap.xml', function sitemaps(req) {
    let host = Meteor.absoluteUrl();
    if (req && req.headers && {
      host = `http://${}/`;
    return [
      { page: `${host}page1`, lastmod: new Date() },
      { page: `${host}page2`, lastmod: new Date() }
1 Like