title: Express detect if request came from a subdomain?
body: <p>I am using npm subdomain, and to keep routing clean I would like to do something like.</p>
  
  <pre><code>router.get('/login_success',function(req,res) {
  
    if(req.subdomain) {
      res.redirect('/');
    } else {
      res.sendStatus(200);
    } 
  
  });
  </code></pre>
  
  <p>In the above, if the user logs in the app via sub-domain, I redirect to the sub-domain root which renders a profile. </p>
  
  <p>If the user logs in via the non sub-domain route, it's using ajax to render a view so I need to send a 200 status saying the user is valid.</p>
  
  <p>I figured this is much more clean that having two separate callback routes for each.</p>
  
  <p>So my question, is there a way to detect if the req came from a sub-domain or regular domain. </p>
  
  <p>I know there is <code>req.headers.origin</code> but I am wondering if there is a more relative way of doing it, so when going back and forth between local and production I don't have to change it.</p>