簡體   English   中英

ActionController :: RoutingError沒有與“ / cloudfoundryapplication”匹配的[GET]和[OPTION]路由

[英]ActionController::RoutingError No route matches [GET] & [OPTION] for “/cloudfoundryapplication”

我在Pivotal Web服務上使用Puma運行Rails 5.1.3。 自從Rails 4升級到此版本后,我看到以下錯誤出現在日志中:

1. ActionController::RoutingError (No route matches [GET] "/cloudfoundryapplication")
2. ActionController::RoutingError (No route matches [OPTION] "/cloudfoundryapplication")

我在Pivotal的“ / cloudfoundryapplication”上找不到任何詳細信息,但是由於我認為它是一個外部應用程序,因此可能與跨域資源共享(CORS)有關。 然后,我使用“ rack-cors” gem嘗試解決此問題。 結果是[OPTION]錯誤消失了,但[GET]錯誤消失了。

這是我的config / application.rb:

require_relative 'boot'

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
require 'pdfkit'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.

Bundler.require(*Rails.groups)

module MyFaro
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.1

    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    config.time_zone = 'Brussels'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    #config.i18n.load_path = Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
    config.i18n.default_locale = :nl

    #config.skylight.probes += %w(mongoid mongo)

    config.middleware.use PDFKit::Middleware, {:print_media_type => true}, :only => %r[/print_story]

    config.after_initialize do
      ApplicationController.helpers.cache_set_look_up_hash
      ApplicationController.helpers.cache_set_system_parameter_hash
    end
  end
end

和我的config / environments / production.rb:

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  #CORS
  config.middleware.insert_before 0, Rack::Cors do
    allow do
      origins '*'
      resource '*', :headers => :any, :methods => [:get, :post, :options]
    end
  end

  # Code is not reloaded between requests.
  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.cache_store = :memory_store

  # Attempt to read encrypted secrets from `config/secrets.yml.enc`.
  # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
  # `config/secrets.yml.key`.
  config.read_encrypted_secrets = true

  # Disable serving static files from the `/public` folder by default since
  # Apache or NGINX already handles this.
  config.public_file_server.enabled = true

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = true

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = 'http://assets.example.com'

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

  # Mount Action Cable outside main process or domain
  # config.action_cable.mount_path = nil
  # config.action_cable.url = 'wss://example.com/cable'
  # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
   config.force_ssl = true

  # Use the lowest log level to ensure availability of diagnostic information
  # when problems arise.
  config.log_level = :error

  # Prepend all log lines with the following tags.
  config.log_tags = [ :request_id ]

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Use a real queuing backend for Active Job (and separate queues per environment)
  # config.active_job.queue_adapter     = :resque
  # config.active_job.queue_name_prefix = "my_faro_#{Rails.env}"
  config.action_mailer.perform_caching = false

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.default_url_options = { host: 'http://myfaro.cfapps.io/'}
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
      address: 'smtp.mailgun.org',
      port: 587,
      authentication: 'plain',
      #domain: 'sandboxe3e6f1cfc3d34efc8dba23c1a1eaff8b.mailgun.org',
      domain: 'mg.myfaro.be',
      #user_name: 'postmaster@sandboxe3e6f1cfc3d34efc8dba23c1a1eaff8b.mailgun.org',
      user_name: 'postmaster@mg.myfaro.be',
      #password: '25c695256391ca3e9f6c6bb1dd9f622f'
      password: 'f1d6d58994362f084cc2ecac0e46256c'
  }
  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true
  config.i18n.available_locales = [:en,:nl,:fr,:de]

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Use a different logger for distributed setups.
  # require 'syslog/logger'
  # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger    = ActiveSupport::TaggedLogging.new(logger)
  end

end

我從Pivotal支持團隊得到了答復。

Pivotal Web Services的Apps Manager使用/ cloudfoundryapplication端點作為Spring Boot Actuator集成的根。 當您在Apps Manager UI中查看該應用程序時,它將為該應用程序調用此端點,無論您是否已為Apps Manager配置了Spring Boot Actuator端點。

因此,對於不使用Spring Boot Actuator端點的應用程序,這些錯誤僅在使用Apps Manager GUI時出現。

它就像冰箱里的薛定ers的光貓:如果不看,就不會出現錯誤。 我通過CLI檢查了日志,實際上根本沒有任何錯誤。

從應用程序的config/routes.rb借一行:

match '/cloudfoundryapplication', to: proc { [200, {}, ['']] }, via: %i[get options]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM