[英]Faye Websocket Error Rails 2.2.2 (production)
我一直在2.1.3上使用Faye沒問題,但是升級到2.2.2后,我只能使本地實例正常工作。 生產websocket失敗。 我將實際的服務器名稱替換為blahblahserver.com
菲·拉克普(Faye Rackup)
require 'faye'
app = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)
Faye::WebSocket.load_adapter('thin')
run app
Application.html.erb
<%= javascript_include_tag "application",params[:controller],'http://app-server1.blahblahserver.com:9292/faye/faye.js','data-turbolinks-track' => true %>
助手(發送功能)
def broadcast(channel, &block)
message = {:channel => channel, :data => capture(&block)}
uri = URI.parse("http://localhost:9292/faye")
Net::HTTP.post_form(uri, :message => message.to_json)
end
In Rails控制器
gon.env = Rails.env
聽眾(咖啡)
$ ->
# required when faye listener is present to keep from having hard env changes
# parallel gon.env = Rails.env in controller must be present
server_name = undefined
switch gon.env
when "production"
server_name = 'app-server1.blahblahserver.com'
when "staging"
server_name = 'si-staging.blahblahserver.com'
when "development"
server_name = 'localhost'
address = 'http://' + server_name + ':9292/faye'
# Listener for this page locally
faye = new (Faye.Client)(address)
faye.subscribe ('/logs/'+gon.property_id+ '/new'), (data) ->
if getParameterByName('all_open') == "true"
window.location.href = window.location.href
else if gon.today == gon.display_date
ready(data)
else window.location.href = window.location.href
return
faye.subscribe ('/logs/'+gon.property_id+ '/alert'), (data) ->
console.log('pre-ajax')
$.ajax 'load_customer_messages' ,
type: "GET",
dataType: "JSON",
asnyc: false,
success: (data2) ->
$('#ajax').click()
return
return
ready = (data) ->
eval data
因此,問題出在Faye的升級上。 現在開始的語法如下:
rackup --host [服務器的IP地址] faye.ru -s薄-E生產-D現在需要添加--host [ip地址],因為rackup不再在沒有IP地址的情況下進行外部偵聽。
6天的挫敗感,在faye網站上沒有文檔!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.