expressjs / vhost

virtual domain hosting
MIT License
761 stars 87 forks source link

Add ability to pass an array of hostnames #15

Closed ssimpo closed 9 years ago

ssimpo commented 9 years ago

I needed the ability to pass an array of hostnames to vhost, so tweaked the code a little to do this.

Admittedly, this could be achieved with a carefully constructed RegEx. However, in some circumstances it is cleaner to pass array. If the configs for each vhost are in a json file, it's nice to use an array. Much easier to read than a RegEx.

Eg:

vhost([
    'loaclhost.example.org',
    'example.org',
    'www.example.org'
], app);
dougwilson commented 9 years ago

Hi! Thank you so much for the contribution! Unfortunately due to the complexity this introduces, and our similar experience with excepting arrays of strings/regexs as paths in Express, we're going to have to decline this PR. You can easily implement this functionality yourself, or even publish it to npm. For example:

var Router = require('router')
var vhost = require('vhost')

module.exports = multiVhost(arr, handle) {
  var router = new Router()

  arr.forEach(function (hostname) {
    router.use(vhost(hostname, handle))
  })

  return router
}