I am using npm subdomain, and to keep routing clean I would like to do something like.
router.get('/login_success',function(req,res) {
  if(req.subdomain) {
    res.redirect('/');
  } else {
    res.sendStatus(200);
  } 
});
In the above, if the user logs in the app via sub-domain, I redirect to the sub-domain root which renders a profile.
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.
I figured this is much more clean that having two separate callback routes for each.
So my question, is there a way to detect if the req came from a sub-domain or regular domain.
I know there is req.headers.origin 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.
Use req.subdomains, this will give you a list of subdomains used in the url. Here's where I got the information from.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With