Created
October 31, 2018 12:35
-
-
Save ChukwuEmekaAjah/45a7fbc15b6bf7846acf8285db422b51 to your computer and use it in GitHub Desktop.
Creating a vhost object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function vhostof(req, regexp) { | |
var host = req.headers.host | |
var hostname = hostnameof(req) | |
if (!hostname) { | |
return | |
} | |
var match = regexp.exec(hostname) | |
if (!match) { | |
return | |
} | |
var obj = Object.create(null) | |
obj.host = host | |
obj.hostname = hostname | |
obj.length = match.length - 1 | |
for (var i = 1; i < match.length; i++) { | |
obj[i - 1] = match[i] | |
} | |
return obj | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment