sub-packs/themes/zealder-admin-theme/lib/middleware.js
function siteAppsAdmin(req, res, cb) {
  var { themeData } = res.locals;
  const { apps, getInheritTheme, themes } = req.app.locals;

  if (!themeData.managingSite) cb();
  else {
    // provide function for apps/themes to add pages
    res.locals.addPages = function(appPages) {
      addPages(req, res, appPages);
    }

    let mgSiteApps = themeData.authSites[themeData.managingSite].zsApps;
    if (mgSiteApps) {
      req.app.debug('Site has apps %o', mgSiteApps);

      // iterate managingSite apps
      _.forEach(mgSiteApps, function(key) {
        if (apps[key] && apps[key].main) {
          let main = require(`${apps[key].path}/${apps[key].main}`);

          // check if middleware for admin is provided
          if (main.admin) {
            main.admin(req, res);
          }
        }
      });
    }

    let mgSiteTheme = themeData.authSites[themeData.managingSite].zsTheme;
    if (mgSiteTheme) {
      let themeTree = getInheritTheme(mgSiteTheme);
      // iterate managingSite themetree
      _.forEach(themeTree, function(v, key) {
        if (themes[key] && themes[key].main) {
          let main = require(`${themes[key].path}/${themes[key].main}`);

          // check if middleware for admin is provided
          if (main.admin) {
            main.admin(req, res);
          }
        }
      });
    }

    cb();
  }
}
function siteAppsAdmin(req, res, cb) {
  var { themeData } = res.locals;
  const { apps, getInheritTheme, themes } = req.app.locals;

  if (!themeData.managingSite) cb();
  else {
    // provide function for apps/themes to add pages
    res.locals.addPages = function(appPages) {
      addPages(req, res, appPages);
    }

    let mgSiteApps = themeData.authSites[themeData.managingSite].zsApps;
    if (mgSiteApps) {
      req.app.debug('Site has apps %o', mgSiteApps);

      // iterate managingSite apps
      _.forEach(mgSiteApps, function(key) {
        if (apps[key] && apps[key].main) {
          let main = require(`${apps[key].path}/${apps[key].main}`);

          // check if middleware for admin is provided
          if (main.admin) {
            main.admin(req, res);
          }
        }
      });
    }

    let mgSiteTheme = themeData.authSites[themeData.managingSite].zsTheme;
    if (mgSiteTheme) {
      let themeTree = getInheritTheme(mgSiteTheme);
      // iterate managingSite themetree
      _.forEach(themeTree, function(v, key) {
        if (themes[key] && themes[key].main) {
          let main = require(`${themes[key].path}/${themes[key].main}`);

          // check if middleware for admin is provided
          if (main.admin) {
            main.admin(req, res);
          }
        }
      });
    }

    cb();
  }
}
load admin functions for site apps