繁体   English   中英

在Heroku上部署ActionCable(Rails 5 beta4)

[英]Deploy ActionCable on Heroku (Rails 5 beta4)

我在本地主机上有一个具有ActionCable的Rails 5应用程序,并且正在尝试将其部署到heroku。 当访问聊天室所在的页面时,我可以在chrome的控制台中看到:

WebSocket connection to 'wss://full-beyond-9816.herokuapp.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

我在heroku上设置了Redis和Redis插件。 这是我的cable.yml文件的生产部分:

production: &production
  :url: redis://redistogo:4140ce7f3e7493bd1b12@porgy.redistogo.com:9463/
  :host: tarpon.redistogo.com
  :port: 10272
  :password: 12e348ac10ca002879ce7d85daf0bb0
  :inline: true
  :timeout: 1

这是我的room.coffee文件:

(function() {
  this.App || (this.App = {});

  App.cable = ActionCable.createConsumer();

}).call(this);

在heroku上设置ActionCable似乎很棘手,而且我在该主题上发现的每条帖子都使用Phusion Passenger(我正在使用Puma)或使用相当老版本的ActionCable(我正在使用最新的Rails 5 Beta) )。

我应该如何设置? 感谢您的时间和帮助

很难从您的错误中分辨出来。 我确实使用Redis插件和Puma在Heroku上部署了ActionCable。 尽管我不得不承认,由于ActionCable是超新技术,因此很难获得任何支持。 我不得不四处游玩以使其正常运行。

就您而言,您可能遇到了问题。 查看文件config / environments / production.rb,取消注释以下部分并添加您的heroku应用名称:

  # Action Cable endpoint configuration
  config.action_cable.url = 'wss://yourappname.herokuapp.com/cable'
  config.action_cable.allowed_request_origins = [ 'https://yourappname.herokuapp.com', /http:\/\/yourappname.herokuapp.com.*/ ]

以防万一,这里是我的cable.yml文件:

# Action Cable uses Redis by default to administer connections, channels, and sending/receiving messages over the WebSocket.
production:
  adapter: redis
  url: add-hereyour-redis-url-from-heroku-redis-to-go-addon

development:
  adapter: async

test:
  adapter: async

另外,不要忘了添加宝石Redis在生产中运行Action Cable。 关于room.coffee文件fyi,它应该看起来像这样(这意味着客户端需要设置此连接的使用者实例):

#= require action_cable
#= require_self
#= require_tree .

@App = {}
App.cable = ActionCable.createConsumer()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM