David Mckee
David Mckee

Reputation: 1180

How do sites like Freshbooks and Harvest create individual platforms on different subdomains?

The site I am trying to create will have separate subdomains for each primary admin account. For the purpose of this question, let's say Google is a customer, so when they register, I need to create the subdomain "google.mysite.com".

From there, different individuals (admin, employees, clients) with different privileges can then log in to the google.mysite.com.

I am using Ruby on Rails as a platform and am a bit lost as to how I would go about doing this. What is a solid approach?

Upvotes: 1

Views: 229

Answers (2)

Matt
Matt

Reputation: 74879

On the operational side, you need to setup your DNS and infrastructure to support this on top of the Ruby code.

Wildcard subdomains

A wild card solution will be the easiest to setup as you only need the do the initial setup and any new sub domains will fall into line.

A Wildcard DNS record will map all of *.mysite.com in a single record.

Web servers like Apache httpd and Nginx support wildcard virtualhosts as well as application hosts like Heroku so you can house all your sub domains under the one config.

Individual subdomains

Individual sub domains may provide more flexibility in the future for things like load seperation or custom configs on a per domain basis, but will require initial setup each time one of your customers signs up which can involve things outside your Rails App.

For DNS records, I would use a DNS host that provides API's into their administration, like Amazon Route 53 or Rackspace Cloud DNS.

For Ruby hosting with API config you might be looking at one of the application hosts like Heroku as I've not seen a lot of "web hosting" services on the cloud providers with config API's, unless it's for static files.

Internal hosting

If your want to host the sites internally it would probably be easier to use one of the API's exposed by hosting control panel products like Plesk or cpanel that support web and DNS configuration out of the box rather than rolling your own.

Upvotes: 0

louiedp3
louiedp3

Reputation: 78

This is where constraint-based routing can help. By setting a route to accept any subdomain like so

get 'photos', constraints: { subdomain: /.+/ }

We can then allow the controller to act based on request.subdomain. Railscast has a good example.

I also believe that the devise gem also offers a similar solution.

Upvotes: 1

Related Questions