2015-02-06 96 views
0

我在openshift上部署了一個應用程序,並且我想使用web套接字實現一個聊天應用程序,所以我使用了faye。它在本地工作,但在部署到openshift時,服務器上出現握手錯誤。 這是我config.ru文件:Openshift:在WebSocket握手期間使用faye獲取錯誤

require ::File.expand_path('../config/environment', __FILE__) 
require 'faye' 
use Faye::RackAdapter, :mount => '/faye', :timeout => 25 
run Rails.application 

當我試圖運行https://myapp.rhcloud.com/faye.js這是工作,也是我的應用功能,工作正常。但我收到此錯誤:

WebSocket connection to 'wss://friendsbook-cisinlabs.rhcloud.com/faye' failed 

的application.js

$(function(){ 
    var faye = new Faye.Client('https://myapp.rhcloud.com/faye'); 
    faye.subscribe("/messages/new", function(data) { 
    eval(data); 
    }); 
}); 

application.html.erb

<%= javascript_include_tag '//myapp.rhcloud.com/faye.js' %> 

message_helper.rb

def broadcast(channel, &block) 
    message = {:channel => channel, :data => capture(&block)} 
    uri = URI.parse("https://myapp.rhcloud.com/faye") 
    Net::HTTP.post_form(uri, :message => message.to_json) 
end 

消息/ index.html.erb

<ul id="chat"> 
    <%= render @messages %> 
</ul> 

<%= form_for Message.new, :remote => true do |f| %> 
    <%= f.text_field :content %> 
    <%= f.submit "Send" %> 
<% end %> 

消息/ create.js.erb

<% broadcast "/messages/new" do %> 
    $("#chat").append("<%= escape_javascript render(@message) %>"); 
<% end %> 
$("#new_message")[0].reset(); 

消息/ _message.html.erb

<li> 
    <span class="created_at"><%= message.created_at.strftime("%H:%M") %></span> 
    <%= message.content %> 
</li> 

我推薦來自瑞安貝茨的這個railscast插曲: http://railscasts.com/episodes/260-messaging-with-faye

另外我提到了許多其他的鏈接,但沒有任何幫助。

編輯

我在添加該代碼.openshift/action_hooks/post_start_ruby

nohup bundle exec rackup config.ru -s thin -E production -o $OPENSHIFT_INTERNAL_IP -p 8443 > $OPENSHIFT_HOMEDIR/diy-0.1/logs/server.log 2>&1 &

現在我得到錯誤:

ReferenceError: Faye is not defined

這是我在如何定義王菲的application.js

var faye = new Faye.Client('https://friendsbook-cisinlabs.rhcloud.com:8443/faye

也許它並不起步於8443端口,應該怎麼說來完成。

+0

不使用'https'改用'wss'作爲以下在Corey的帖子中提到 – ImranNaqvi 2015-12-02 06:06:00

回答

3

如果你想使用WSS爲您的連接,你需要使用8443端口,而不是端口443(這是默認)

wss://friendsbook-cisinlabs.rhcloud.com:8443/faye 
+0

是的,它的工作原理 - @shobhit shukla應該標記爲答案 – ImranNaqvi 2015-12-02 06:05:00

相關問題