Joel M.
Joel M.

Reputation: 301

Custom Subdomains in Sinatra app

I want my Sinatra app to allow users to create an account and access it via a subdomain (i.e. your-account.myapp.com).

I found this to extract subdomains (http://gist.github.com/55784#file_subdomains.rb) but I'm having a hard time implementing it.

Any ideas?

I have an Account model (datamapper) with a field called account name, which should be the subdomain.

Thanks!

Upvotes: 3

Views: 1922

Answers (1)

seixasfelipe
seixasfelipe

Reputation: 161

Sinara uses Rack to interact with the webserver.

You could put a Rack middleware before all requests to extract the subdomain, store it on a local variable and use it wherever you need load that user.

I've found 2 resources that could help you: https://github.com/fnando/sinatra-subdomain

and

http://tannerburson.com/2009/01/extracting-subdomains-in-sinatra.html

Regards!

Upvotes: 6

Related Questions