我正在使用actioncable进行聊天功能。当我在本地测试时,它工作得很好,但是当我部署到Heroku时,我得到了这个错误:
'WebSocket连接到'wss:// dg-automotive-portal- rails.herokuapp.com/cable'失败:WebSocket握手期间出错:意外的响应代码:404'
production.rb:
config.action_cable.url = 'wss://dg-automotive-portal-
rails.herokuapp.com/cable'
config.action_cable.allowed_request_origins = [
'https://dg-automotive-portal.herokuapp.com/', 'http://dg-
automotive-portal.herokuapp.com/' ]
cable.yml:
production:
adapter: redis
url:redis:MYURL
routes.rb有
mount ActionCable.server => '/cable'
我安装了redis gem。有没有人知道为什么我在部署时不起作用?
在componentWillMount上调用的Javascript代码:
createSocket() {
let cable = Cable.createConsumer('wss://dg-automotive-portal-rails.herokuapp.com/cable')
this.chats = cable.subscriptions.create({
channel: 'ChatChannel'
}, {
connected: () => {
console.log("connected!")
},
received: (data) => {
this.setState({
chatLogs: [...this.state.chatLogs, data]
})
},
create: function(chatContent, datetime, currentUser) {
this.perform('create', {
content: chatContent,
time: datetime,
user_id: currentUser
})
}
})
}