Skip to content

Instantly share code, notes, and snippets.

@ChukwuEmekaAjah
Created October 31, 2018 12:35
Show Gist options
  • Save ChukwuEmekaAjah/45a7fbc15b6bf7846acf8285db422b51 to your computer and use it in GitHub Desktop.
Save ChukwuEmekaAjah/45a7fbc15b6bf7846acf8285db422b51 to your computer and use it in GitHub Desktop.
Creating a vhost object.
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