Action Cable Server
Configuration
可以通过 ActionCable.server
.config 获取此配置对象的实例,这允许你在 Rails
的配置初始化器中调整 Action Cable 配置。
方法
- N
- P
属性
[RW] | allow_same_origin_as_host | |
[RW] | allowed_request_origins | |
[RW] | cable | |
[RW] | connection_class | |
[RW] | disable_request_forgery_protection | |
[RW] | filter_parameters | |
[RW] | health_check_application | |
[RW] | health_check_path | |
[RW] | log_tags | |
[RW] | logger | |
[RW] | mount_path | |
[RW] | precompile_assets | |
[RW] | url | |
[RW] | worker_pool_size |
类公共方法
new() 链接
源代码: 显示 | 在 GitHub 上
# File actioncable/lib/action_cable/server/configuration.rb, line 22 def initialize @log_tags = [] @connection_class = -> { ActionCable::Connection::Base } @worker_pool_size = 4 @disable_request_forgery_protection = false @allow_same_origin_as_host = true @filter_parameters = [] @health_check_application = ->(env) { [200, { Rack::CONTENT_TYPE => "text/html", "date" => Time.now.httpdate }, []] } end
实例公共方法
pubsub_adapter() 链接
返回 config/cable.yml 中指定的订阅适配器的常量。如果找不到适配器,则默认为 Redis 适配器。同时确保加载正确的依赖关系。
源代码: 显示 | 在 GitHub 上
# File actioncable/lib/action_cable/server/configuration.rb, line 40 def pubsub_adapter adapter = (cable.fetch("adapter") { "redis" }) # Require the adapter itself and give useful feedback about # 1. Missing adapter gems and # 2. Adapter gems' missing dependencies. path_to_adapter = "action_cable/subscription_adapter/#{adapter}" begin require path_to_adapter rescue LoadError => e # We couldn't require the adapter itself. Raise an exception that points out # config typos and missing gems. if e.path == path_to_adapter # We can assume that a non-builtin adapter was specified, so it's either # misspelled or missing from Gemfile. raise e.class, "Could not load the '#{adapter}' Action Cable pubsub adapter. Ensure that the adapter is spelled correctly in config/cable.yml and that you've added the necessary adapter gem to your Gemfile.", e.backtrace # Bubbled up from the adapter require. Prefix the exception message with some # guidance about how to address it and reraise. else raise e.class, "Error loading the '#{adapter}' Action Cable pubsub adapter. Missing a gem it depends on? #{e.message}", e.backtrace end end adapter = adapter.camelize adapter = "PostgreSQL" if adapter == "Postgresql" "ActionCable::SubscriptionAdapter::#{adapter}".constantize end