具有子域约束的​​Heroku路由崩溃

时间:2017-04-11 05:34:36

标签: ruby-on-rails heroku

我的routes.rb中包含此代码,该代码在我的本地计算机上运行良好。但是,当部署到Heroku时,它会崩溃服务器并且路由不会加载任何页面。

class NoSubdomain
  def self.matches?(request)
    !request.subdomain.present?
  end
end

Rails.application.routes.draw do

  constraints(NoSubdomain) do
    # Routes without subdomain
  end

  constraints lambda { |req| req.format == :json && req.subdomain == 'api' } do
    namespace :crew do
      scope module: :api do # For API folder to organise files
        namespace :v1 do
          # Routes with subdomain
        end
      end
    end
  end
end

我怎样才能让它发挥作用?

以下是错误日志:

2017-04-11T02:41:59.236210+00:00 app[web.1]: App 136 stdout: ActionController::RoutingError (No route matches [GET] "/"):
2017-04-11T02:41:59.236211+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2017-04-11T02:41:59.236212+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.17.1.326/lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
2017-04-11T02:41:59.236213+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2017-04-11T02:41:59.236213+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.17.1.326/lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
2017-04-11T02:41:59.236214+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/lograge-0.4.1/lib/lograge/rails_ext/rack/logger.rb:15:in `call_app'
2017-04-11T02:41:59.236216+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/rack/logger.rb:20:in `block in call'
2017-04-11T02:41:59.236216+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:68:in `block in tagged'
2017-04-11T02:41:59.236217+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:26:in `tagged'
2017-04-11T02:41:59.236219+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:68:in `tagged'
2017-04-11T02:41:59.236220+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/rack/logger.rb:20:in `call'
2017-04-11T02:41:59.236221+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/quiet_assets-1.1.0/lib/quiet_assets.rb:27:in `call_with_quiet_assets'
2017-04-11T02:41:59.236222+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.17.1.326/lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
2017-04-11T02:41:59.236224+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2017-04-11T02:41:59.236224+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.17.1.326/lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
2017-04-11T02:41:59.236226+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/rack-1.6.5/lib/rack/methodoverride.rb:22:in `call'
2017-04-11T02:41:59.236244+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.17.1.326/lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
2017-04-11T02:41:59.236245+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/rack-1.6.5/lib/rack/runtime.rb:18:in `call'
2017-04-11T02:41:59.236262+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.17.1.326/lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
2017-04-11T02:41:59.236263+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
2017-04-11T02:41:59.236265+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.17.1.326/lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
2017-04-11T02:41:59.236267+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/static.rb:120:in `call'
2017-04-11T02:41:59.236285+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.17.1.326/lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
2017-04-11T02:41:59.236286+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/rack-1.6.5/lib/rack/sendfile.rb:113:in `call'
2017-04-11T02:41:59.236286+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.17.1.326/lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
2017-04-11T02:41:59.236289+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/ssl.rb:24:in `call'
2017-04-11T02:41:59.236290+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.17.1.326/lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
2017-04-11T02:41:59.236292+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/rack-mini-profiler-0.10.1/lib/mini_profiler/profiler.rb:171:in `call'
2017-04-11T02:41:59.236312+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.17.1.326/lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
2017-04-11T02:41:59.236313+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/engine.rb:518:in `call'
2017-04-11T02:41:59.236313+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/application.rb:165:in `call'
2017-04-11T02:41:59.236334+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.17.1.326/lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
2017-04-11T02:41:59.236335+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
2017-04-11T02:41:59.236336+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:152:in `accept_and_process_next_request'
2017-04-11T02:41:59.236337+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'
2017-04-11T02:41:59.236337+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'
2017-04-11T02:41:59.236338+00:00 app[web.1]: App 136 stdout:   vendor/bundle/ruby/2.3.0/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'    

更新

以下是有关路线的更多信息(不是整个文件,有50​​0行)

require 'sidekiq/web'

class NoSubdomain
  def self.matches?(request)
    !request.subdomain.present?
  end
end

Rails.application.routes.draw do

  constraints(NoSubdomain) do
    devise_for :users, controllers: {invitations: 'admin/invitations', registrations: 'users/registrations', passwords: 'users/passwords'}
    resources :users

    devise_scope :user do

      authenticated :user do

        # Admin dashboard
        namespace :admin do
          resources :keywords
        end

        namespace :customer do
          get 'dashboard', to: 'dashboard#main'
        end

        namespace :crew do
          get 'schedule', to: 'schedule#index'
        end

        # Role based redirect - # PassthroughController
        root to: 'passthrough#index'
      end

      unauthenticated :user do
        # redirects if not logged in
        match '/admin(/*path)' => 'devise/sessions#new', via: :get
        match '/crew(/*path)' => 'devise/sessions#new', via: :get
        match '/customer(/*path)' => 'devise/sessions#new', via: :get
      end

    end

    namespace :shared, path: '/' do
      get 'ajax_update_page', to: 'ajax_quote#update_page'
    end

    namespace :public do
      get 'invitations/accept/:invitation_token', to: 'invitations#edit', as: 'invitations_edit'
      patch 'invitations/accept/:invitation_token', to: 'invitations#update', as: 'invitations_update'
    end

    namespace :shared, path:'/' do
      get 'find_availabilities', to: 'availabilities#find_availabilities'
      get 'find_available_dates', to: 'availabilities#find_available_dates'
      resources :attachments
    end

    namespace :public, path: 'booking_steps' do
      # get 'ideal_booking_time', to: 'booking_steps#ideal_booking_time'
      patch 'update_mixpanel_alias_created', to: 'booking_steps#update_mixpanel_alias_created'
      resources :booking_steps, only: [:index, :show, :update], path: ''
    end

    namespace :api do
      get 'crew_birthdays', to: 'crew_birthdays#index'
    end

    root to: 'public/pages#index', as: 'landing'
  end



  # For Rails 4, lambda needs to be used to restrict the format of the request
  # http://stackoverflow.com/a/37603236/1076279
  constraints lambda { |req| req.format == :json && req.subdomain == 'api' } do
    namespace :crew do
      scope module: :api do
        namespace :v1 do
          namespace :jobs do
            resources :jobs, only: :show
          end
        end
      end
    end
  end
end

0 个答案:

没有答案