middleware/mw.app.context.js
function setAppInfo(req, domainMap) {
        var host = req.info.hostname;
        var domain;

        // hack fix for m.reviews, m.fr, m.es, etc.
        if (host.substring(0, 2) === 'm.') {
            req.app.isLegacyMobile = true;
            host = host.substring(2);
        }

        // if the host starts with the lang, then remove it
        if (host.indexOf(req.app.lang + '.') === 0) {
            host = host.substring(3);
        }

        // if the host name equals the base host then we are dealing with the default domain (ex. gethuman.com)
        if (host === config.baseHost) {
            domain = '';
        }
        // else we need to extract the domain from the host
        else {
            var dotIdx = host.indexOf('.');
            var dashIdx = host.indexOf('-');
            var idx = (dashIdx > 0 && dashIdx < dotIdx) ? dashIdx : dotIdx;
            domain = host.substring(0, idx);
        }

        // get the app name
        var appName = domainMap[domain];

        // if no app name found, try to use the default (else if no default, throw error)
        if (!appName) {
            if (config.webserver && config.webserver.defaultApp) {
                appName = config.webserver.defaultApp;
            }
            else {
                throw AppError.invalidRequestError('No valid domain in requested host: ' + req.info.host);
            }
        }

        // at this point we should have the domain and the app name so set it in the request
        req.app.domain = domain;
        req.app.name = appName;
    }
function setAppInfo(req, domainMap) {
        var host = req.info.hostname;
        var domain;

        // hack fix for m.reviews, m.fr, m.es, etc.
        if (host.substring(0, 2) === 'm.') {
            req.app.isLegacyMobile = true;
            host = host.substring(2);
        }

        // if the host starts with the lang, then remove it
        if (host.indexOf(req.app.lang + '.') === 0) {
            host = host.substring(3);
        }

        // if the host name equals the base host then we are dealing with the default domain (ex. gethuman.com)
        if (host === config.baseHost) {
            domain = '';
        }
        // else we need to extract the domain from the host
        else {
            var dotIdx = host.indexOf('.');
            var dashIdx = host.indexOf('-');
            var idx = (dashIdx > 0 && dashIdx < dotIdx) ? dashIdx : dotIdx;
            domain = host.substring(0, idx);
        }

        // get the app name
        var appName = domainMap[domain];

        // if no app name found, try to use the default (else if no default, throw error)
        if (!appName) {
            if (config.webserver && config.webserver.defaultApp) {
                appName = config.webserver.defaultApp;
            }
            else {
                throw AppError.invalidRequestError('No valid domain in requested host: ' + req.info.host);
            }
        }

        // at this point we should have the domain and the app name so set it in the request
        req.app.domain = domain;
        req.app.name = appName;
    }
function setAppInfo ( req , domainMap ) { var host = req . info . hostname ; var domain ; // hack fix for m.reviews, m.fr, m.es, etc. if ( host . substring ( 0 , 2 ) === 'm.' ) { req . app . isLegacyMobile = true ; host = host . substring ( 2 ) ; } // if the host starts with the lang, then remove it if ( host . indexOf ( req . app . lang + '.' ) === 0 ) { host = host . substring ( 3 ) ; } // if the host name equals the base host then we are dealing with the default domain (ex. gethuman.com) if ( host === config . baseHost ) { domain = '' ; } // else we need to extract the domain from the host else { var dotIdx = host . indexOf ( '.' ) ; var dashIdx = host . indexOf ( '-' ) ; var idx = ( dashIdx > 0 && dashIdx < dotIdx ) ? dashIdx : dotIdx ; domain = host . substring ( 0 , idx ) ; } // get the app name var appName = domainMap [ domain ] ; // if no app name found, try to use the default (else if no default, throw error) if ( ! appName ) { if ( config . webserver && config . webserver . defaultApp ) { appName = config . webserver . defaultApp ; } else { throw AppError . invalidRequestError ( 'No valid domain in requested host: ' + req . info . host ) ; } } // at this point we should have the domain and the app name so set it in the request req . app . domain = domain ; req . app . name = appName ; }
Set the app domain and name
@param req
@param domainMap Key is subdomain value, value is the name of the app
Set the app domain and name