我正在使用padrino websockets(https://github.com/dariocravero/padrino-websockets)为我的网站提供一个聊天系统,本地机器上运行良好。然而,在部署到Heroku免费版后,websocket无法连接并返回。
failed: Connection closed before receiving a handshake response
在本地主机上运行良好,我使用以下内容进行连接:
connection = new WebSocket('ws://localhost:3000/channel');
但是,当在Heroku上使用时,需要这样做:
connection = new WebSocket('ws://******.herokuapp.com:3000/channel');
它返回了一个握手错误(如上所示)
我的实现服务器端
websocket :channel do
on :newmessage do |message|
currentAccount = Account.find_by(lastLoginIP: message["ip"]) rescue nil
if currentAccount != nil
broadcast :channel, {
"name" => currentAccount.nickname,
"url" => currentAccount.url,
"image" => currentAccount.image,
"chatmessage" => message["chatmessage"][0..80]
}
end
end
end
我的主要Padrino app.rb文件中包含了这个,并且在我的Procfile中也有。发生了什么?
web: bundle exec puma -t 1:16 -p ${PORT:-3000} -e ${RACK_ENV:-production}