【发布时间】:2015-12-18 23:34:45
【问题描述】:
我正在使用 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}
【问题讨论】:
标签: heroku websocket sinatra padrino