抽筋和 Heroku
我一直在尝试使用 Cramp 在应用程序中进行一些实时信息推送。它在本地运行得很好,但是当我推送到 Heroku 时,我似乎遇到了端口问题。
我在cramp中设置了一个继承自websocket的套接字
class LiveSocket < Cramp::Websocket
,并且我还有一个名为home的cramp操作,它基本上只是在我的路由文件中为主页呈现一些erb
class HomeAction < Cramp::Action
我设置了以下内容以及一个静态文件服务器
Rack::Builder.new do
puts "public file at #{File.join(File.dirname(__FILE__), '../public')}"
file_server = Rack::File.new(File.join(File.dirname(__FILE__), 'public'))
routes = HttpRouter.new do
add('/').to(HomeAction)
get('/LiveSocket').to(LiveSocket)
end
run Rack::Cascade.new([file_server, routes])
end
然后在客户端结束 javascript 连接到
var ws = new WebSocket("ws://<%= request.host_with_port %>/LiveSocket");
正如我在本地所说,一切正常。我们连接并开始接收来自服务器的通知。在heroku上,我们在Cedar堆栈上运行得很薄,并且有一个配置文件,看起来像
web: bundle exec thin --timeout 0 start -p $PORT
当我加载网站时,页面本身加载正常,但在尝试连接websocket时,我收到一个错误,说
servername.herokuapp.com Unexpected response code: 200
我猜测这与如何处理有关heroku 路由它的请求,但我知道你可以在 heroku 上运行一个 node.js websocket 服务器,所以我想一定有一种方法可以让它工作。
预先感谢您的任何帮助。
干杯
斯图尔特
I have been playing around with Cramp to do some real time pushing of information in an app. Its all working great locally but when I push off to heroku I seem to be having issues with the ports.
I have a socket set up in cramp which inherits from websocket
class LiveSocket < Cramp::Websocket
and I also have a cramp action called home which basically just renders some erb for the home page
class HomeAction < Cramp::Action
in my route file I set up the following and also a static file server
Rack::Builder.new do
puts "public file at #{File.join(File.dirname(__FILE__), '../public')}"
file_server = Rack::File.new(File.join(File.dirname(__FILE__), 'public'))
routes = HttpRouter.new do
add('/').to(HomeAction)
get('/LiveSocket').to(LiveSocket)
end
run Rack::Cascade.new([file_server, routes])
end
Then on the client end the javascript connects to
var ws = new WebSocket("ws://<%= request.host_with_port %>/LiveSocket");
As I say locally it all works. We connect and start receiving notifications from the server. On heroku we run thin on the Cedar stack and have a profile which looks like
web: bundle exec thin --timeout 0 start -p $PORT
When I load up the site the page itself loads fine but on trying to connect the websocket I get an error which says
servername.herokuapp.com Unexpected response code: 200
I am guessing this has something to do with how heroku routes its requests but I do know that you can run a node.js websocket server on heroku so figure there must be a way to get this working too.
Thanks in advance for any help.
cheers
stuart
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为 Heroku 支持 websockets :( http://devcenter.heroku.com/articles /http-routing#the_herokuappcom_http_stack
I don't think Heroku supports websockets :( http://devcenter.heroku.com/articles/http-routing#the_herokuappcom_http_stack