阅读背景:

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

来源:互联网 

I am running Rails 5.1.3 with Puma on Pivotal Web Services. Since upgrading to this version from Rails 4, i am seeing the following errors appear in the logs:

我在Pivotal Web Services上使用Puma运行Rails 5.1.3。从Rails 4升级到此版本后,我发现日志中出现以下错误:

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

I can't find any details on the "/cloudfoundryapplication" on Pivotal but as it an external application i figured it might be related to Cross-Origin Resource Sharing (CORS). I then used the 'rack-cors' gem to try to fix the issue. The effect was that the [OPTION] errors disappeared but not the [GET] errors.

我在Pivotal上找不到关于“/ cloudfoundryapplication”的任何细节,但作为外部应用程序,我认为它可能与跨源资源共享(CORS)有关。然后,我使用'rack-cors'宝石尝试解决问题。结果是[OPTION]错误消失了,但没有[GET]错误。

Here is my config/application.rb:

这是我的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

and my config/environments/production.rb:

和我的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 = 'https://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 = [ 'https://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: 'https://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: '[email protected]',
      user_name: '[email protected]',
      #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

1 个解决方案

#1


0  

I got an answer from the Pivotal support team.

我得到了Pivotal支持团队的答复。

Pivotal Web Services' Apps Manager uses the /cloudfoundryapplication endpoint as the root for Spring Boot Actuator integrations. It calls this endpoint for an app when you view the app in the Apps Manager UI, regardless of whether you have configured Spring Boot Actuator endpoints for Apps Manager.

Pivotal Web Services的Apps Manager使用/ cloudfoundryapplication端点作为Spring Boot Actuator集成的根。当您在Apps Manager UI中查看应用程序时,无论您是否为Apps Manager配置了Spring Boot Actuator端点,它都会为应用程序调用此端点。

So for applications not using the Spring Boot Actuator endpoints these errors appear but only while using the Apps Manager GUI.

因此,对于不使用Spring Boot Actuator端点的应用程序,这些错误只会在使用Apps Manager GUI时出现。

Its like Schrodingers Cat of the Light in the Fridge: if you don't look, the errors don't appear. I checked the logs via the CLI and indeed there are no errors at all.

它就像冰箱里的薛迪格斯之光:如果你不看,那么错误就不会出现了。我通过CLI检查了日志,确实没有任何错误。


分享到: