【发布时间】:2018-01-29 14:47:58
【问题描述】:
我正在尝试让 ActionCable 在子域上工作。
问题是,只要我更改以下行
config.action_cable.mount_path = '/'
该应用程序不再工作。但是 ActionCable 在子域上工作。是否有任何解决方案可以在没有像 /cable 这样的子目录的子域上运行 ActionCable?
【问题讨论】:
-
我也想要这个问题的答案
我正在尝试让 ActionCable 在子域上工作。
问题是,只要我更改以下行
config.action_cable.mount_path = '/'
该应用程序不再工作。但是 ActionCable 在子域上工作。是否有任何解决方案可以在没有像 /cable 这样的子目录的子域上运行 ActionCable?
【问题讨论】:
如果您不使用带有子 uri 的应用内服务器,您似乎需要将其作为独立服务器运行:https://github.com/rails/rails/tree/master/actioncable#consumer-configuration
您可以像这样指定电缆网址:
config.action_cable.url = 'ws://cable.example.com:28080'
有线服务器与您的普通应用服务器分开。它仍然是一个 Rack 应用程序,但它是它自己的 Rack 应用程序。推荐的基本设置如下:
# cable/config.ru
require_relative '../config/environment'
Rails.application.eager_load!
run ActionCable.server
然后你使用 bin/cable ala 中的 binstub 启动服务器:
#!/bin/bash
bundle exec puma -p 28080 cable/config.ru
https://github.com/rails/rails/tree/master/actioncable#standalone
【讨论】: