request-hostname
v1.0.0
Published
Get a proper hostname off of a request object
Downloads
6
Maintainers
Readme
Request Hostname
Get the hostname from a request object. Even if it is IPv6 or from x-forwarded-host
.
Install
$ npm install --save request-hostname
Usage
// Basic stuff
var requestHostname = require('request-hostname');
console.log(requestHostname(req)) // example.com
// Anything that looks like a standard node request object
var request = {
headers: {
host: 'www.example.com'
}
};
console.log(requestHostname(request)) // www.example.com
// Also IPv6 or IPv4 hosts
var IPv6Request = {
headers: {
host: '[2001:0db8:0000:0000:0000:ff00:0042:8329]'
}
};
console.log(requestHostname(IPv6Request)) // 2001:0db8:0000:0000:0000:ff00:0042:8329