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

1

7

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.

Selfpropelled answered 6/11, 2012 at 17:48 Comment(0)
S
7

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/

Selfpropelled answered 6/11, 2012 at 19:56 Comment(2)
`start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError) on starting rails serverCoffelt
Just to call out that using .dev might cause other issues if you're using chrome - #47768789. I would suggest using .test or .localhost insteadTowandatoward

© 2022 - 2024 — McMap. All rights reserved.