How does one allow customers to access a SaaS using their organization name in the domain?
For example, a web app, example.com, may have 2 customers, OrgA and OrgB.
Once logged in, each customer is redirected to their site, orga.example.com / orgb.example.com.
Once the request that includes the subdomain reaches the node server, my hope is to handle the request with a single '/' route. Inside the route handler, it simply inspects the host header and treats the subdomain as a param for the organization.
Something like:
app.get "/*", app.restricted, (req, res) ->
console.log "/* hit with #{req.url} from #{req.headers.host}"
domains = req.headers.host.split "."
if domains
org = domains[0]
console.log org
# TODO. do something with the org name (e.g. load specific org preferences)
res.render "app/index", { layout: "app/app" }
NB. The first item in the domains array is the organization name. I am assuming that no port appears in the host header and, for now, I am not considering how to handle non-organisation sub domain names (e.g. www, blog, etc.).
The question I have is more about how node/express can be configured to handle requests with varying host headers. This is generally solved in Apache using a wildcard alias or in IIS using a host header.
An Apache/Rails example is @ http://37signals.com/svn/posts/1512-how-to-do-basecamp-style-subdomains-in-rails
How can the same be achieved in node?