1602 / compound

MVC framework. Built on Node.JS. Works on server and browser.
http://compoundjs.com
1.6k stars 182 forks source link

New optional virtual host (vhost) feature for routes. #551

Closed jpap closed 11 years ago

jpap commented 11 years ago

A straightforward alternative to the existing subdomain route option.

In the CompoundJS application config/route.coffee file, add the vhost option in the 3rd parameter dictionary:

  exports.routes = (map) ->
    map.get "/apples/:id", "fruit#action", {vhost: ".fruit.com"}
    map.get "/carrots/:id", "vegetable#action", {vhost: "vegetables.com"}

where the vhost value is similar to what you would see in a Nginx server_name directive:

  1. Hostnames starting with a period (".") are treated like wildcards. The first example above matches both "fruit.com" and "www.fruit.com"
  2. Are otherwise are treated as exact matches. The second example above only matches "vegetables.com".
1602 commented 11 years ago

Brilliant. Thank you!