Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subdomain constraint (Rails 3) makes local server (thin) SO SLOW

I recently added a subdomain constraint to my Rails routes file

constraints(:subdomain => 'new') do
  devise_for :customers do 
    get "/customers/sign_up" => "registrations#new"
    post "/customers" => "registrations#create"
    put "/customers/:id" => "registrations#update"
  end
  match '/' => 'roxy#index'
  namespace :roxy, :path => '/' do
    resources :customers
    resources :surveys
  end
end 

In order to test the subdomain routing constraint locally, I added this line to my hosts file.

127.0.0.1       new.localhost.local

Now, I test my app in my browser at the URL new.localhost.local:3000. It takes about 10 - 15 seconds to load every page, which is unreasonably slow. If I remove the subdomain constraint and just go to 127.0.0.1:3000, everything is zippy and fast again.

What am I doing wrong? I'm new to Rails, so please tell me if there is a better way to do subdomain routing in rails, or if there is a setting I need to configure.

like image 436
Maia Bittner Avatar asked Nov 06 '12 17:11

Maia Bittner


1 Answers

Figured it out. It's nothing to do with Rails or subdomains or thin. Turns out, unlike other unixy-things, OS X reserves the .local TLD for mDNS functionality. For every page, the DNS resolution was timing out before loading my app. So I just changed my /etc/hosts file to

127.0.0.1    new.localhost.dev

and everything's working great now.

Read more: http://www.justincarmony.com/blog/2011/07/27/mac-os-x-lion-etc-hosts-bugs-and-dns-resolution/

like image 158
Maia Bittner Avatar answered Mar 04 '23 16:03

Maia Bittner