Slevin
Slevin

Reputation: 4222

Constraints wildcard subdomain

How can I route all subdomains to a controller in a Rails app?

I though something like this would work, but it doesn't:

constraints :subdomain => '*' do
  get '/', :to => 'frontend#index'
  mount API => '/api'
end

Subdomains like

foo.example.com
bar.example.com

should be directed to frontend#index while

foo.example.com/api
bar.example.com/api

should call the Grape API.

Upvotes: 0

Views: 488

Answers (1)

Max Woolf
Max Woolf

Reputation: 4058

Use a regular expression:

constraints :subdomain => /./ do...

Haven't tested it, but something like that should work.

Upvotes: 1

Related Questions