utils.js 536 B

1234567891011121314
  1. exports.originalOrigin = function(req, options) {
  2. options = options || {};
  3. var app = req.app;
  4. if (app && app.get && app.get('trust proxy')) {
  5. options.proxy = true;
  6. }
  7. var trustProxy = options.proxy;
  8. var proto = (req.headers['x-forwarded-proto'] || '').toLowerCase()
  9. , tls = req.connection.encrypted || (trustProxy && 'https' == proto.split(/\s*,\s*/)[0])
  10. , host = (trustProxy && req.headers['x-forwarded-host']) || req.headers.host
  11. , protocol = tls ? 'https' : 'http';
  12. return protocol + '://' + host;
  13. };