all files / express-stormpath/lib/helpers/ parent-domain-redirect.js

37.5% Statements 3/8
0% Branches 0/2
0% Functions 0/1
37.5% Lines 3/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                                         
'use strict';
 
var url = require('url');
var getHost = require('./get-host');
 
/**
* Redirects a request to the same path and port on a parent domain of the
* current sub-domain.
*
* @private
* @method
*
* @param {Object} req - HTTP request
* @param {Object} res - HTTP response
*/
module.exports = function (req, res) {
  var config = req.app.get('stormpathConfig');
  var parsedUrl = url.parse(req.protocol + '://' + getHost(req));
  var port = parsedUrl.port ? (':' + parsedUrl.port) : '';
  var pathname = url.parse(req.url).pathname;
 
  res.redirect(req.protocol + '://' + config.web.domainName + port + pathname);
};