connect-domains

Parse req.headers.host into a heiarchy of domains and sub-domains populating the 'req.domains' object.

npm install connect-domains
3 downloads in the last week
7 downloads in the last month

connect-domains

Parse req.headers.host into a heiarchy of domains and sub-domains populating the 'req.domains' object.

Example

var express = require('express');
var app = express();
// ...
app.use(require('connect-domains')("example.com"));
app.use(function(req,res){
    //when visiting "www.sub1.example.com"
    console.log(req.domains[0]);//#"example.com"
    console.log(req.domains[1]);//#"sub1"
    console.log(req.domains[2]);//#"www"
    console.log(req.domains).join("/");//#"example.com/sub1/www"
})
app.listen(8080);
npm loves you