Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    connect-domainspublic

    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);

    Keywords

    none

    install

    npm i connect-domains

    Downloadsweekly downloads

    3

    version

    0.0.1

    license

    none

    repository

    githubgithub

    last publish

    collaborators

    • avatar