Multi-domain subdomain configuration in Ruby on Rails

How can I have tiered subdomains in ruby ​​on rails?

Currently, if I want to create a subdomain, I configure that route.rb.

constraints :subdomain => 'my' do
   mount API => '/'
    mount GrapeSwaggerRails::Engine => '/documentation'
end

      

This will create support for my.domain.com

However, if I want to have one more api.my.domain.com level, what can I do to have another subdomain level in routes? Thank.

+3


source to share


1 answer


You can nest your own subdomain definitions. Subdomain constraints can be regular expressions, so you can do something like



constraints subdomain: /.*my/ do
  constraints subdomain: 'api.my' do 
    mount API => '/'
    mount GrapeSwaggerRails::Engine => '/documentation'
  end

  # Non-API my subdomain routes
end

      

+2


source







All Articles