gpt4 book ai didi

ruby-on-rails - production.rb 中的 force_ssl - 如何在 Controller 中覆盖为 http

转载 作者:行者123 更新时间:2023-12-04 20:06:20 25 4
gpt4 key购买 nike

在我的 production.rb 中,我有

  config.force_ssl = true

并希望提供异常(exception)。看起来这应该有效(找不到如何回到 3.2.19):
class ApiItemsController < ApplicationController

force_ssl except: :get_item_test

但事实并非如此。我见过 Rails 3.2 force_ssl except on landing page但真的不想为这种微不足道的事情添加 gem 。我如何让这个工作?

编辑 1

enter image description here

最佳答案

@brad-werth 是完全正确的,HTS header 使这成为您可能不想做的事情。但无论如何我一直想这样做,所以这就是我学到的:

在 Rails 5 上(根据 ActionDispatch::SSL docs):

config.ssl_options = { redirect: { exclude: -> request { request.path =~ /health_check/ } } }

在 Rails 4(和一些 Rails 3 版本)中,您必须使用单独的 gem。或者,如果可以在中间件中执行所需的操作,则可以尝试以下操作:
# config/environments/production.rb
config.middleware.insert_before 'ActionDispatch::SSL', 'HealthCheck'

# app/middleware/health_check.rb
class HealthCheck
def initialize(app)
@app = app
end
def call(env)
if env['REQUEST_PATH'] == '/health_check'
return [200, {}, []]
else
@app.call(env)
end
end
end

据报道,某些版本的 Rails 3 支持某些内容 like this :
config.ssl_options = { exclude: proc { |env| env['PATH_INFO'].start_with?('/health_check')} }

要回答实际提出的问题 config.force_ssl环境中的设置是 quite different从使用 force_ssl在 Controller 中,不能以这种方式覆盖。

关于ruby-on-rails - production.rb 中的 force_ssl - 如何在 Controller 中覆盖为 http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25771030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com