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

假装没事ソ 提交于 2019-12-07 03:58:40

问题


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.


回答1:


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/



来源:https://stackoverflow.com/questions/13256485/subdomain-constraint-rails-3-makes-local-server-thin-so-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!