1

我在 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")

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

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

和我的配置/环境/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
4

2 回答 2

1

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

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

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

就像冰箱里的薛定谔猫:如果你不看,错误就不会出现。我通过 CLI 检查了日志,确实没有任何错误。

于 2017-11-24T17:00:57.850 回答
0

从应用程序中借用一行config/routes.rb

match '/cloudfoundryapplication', to: proc { [200, {}, ['']] }, via: %i[get options]
于 2019-09-17T07:33:19.710 回答