all files / express-stormpath/lib/helpers/ is-root-domain-multi-tenant-request.js

100% Statements 5/5
25% Branches 1/4
100% Functions 1/1
100% Lines 5/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                              30× 30×   30×          
'use strict';
 
var getHost = require('./get-host');
 
/**
* Checks whether the given request is targeting the root domain, in an application
* configured to handle multi-tenancy using the `subdomain` strategy.
*
* @method
* @private
*
* @param {Object} req - HTTP request
* @return {Boolean} - Whether this is a root domain request in a subdomain
* multi-tenancy flow.
*
*/
module.exports = function isRootDomainMultiTenantRequest(req) {
  var domain = getHost(req, true);
  var config = req.app.get('stormpathConfig');
 
  return config.web.multiTenancy.enabled
    && config.web.multiTenancy.strategy === 'subdomain'
    && config.web.domainName
    && domain === config.web.domainName;
};