2012-12-05 48 views
0

我正在開發一個流媒體服務器,它使用Goliath和SSE實時發送最新的推文,新聞等實時更新。該服務器將被映射到不同的域。CORS SSE - 未捕獲錯誤:SECURITY_ERR:DOM異常18

的index.html

<script> 
    if(typeof(EventSource)!=="undefined") { 
     var source = new EventSource('http://192.168.0.44:9000/api/stream/articles?channel=Headlines'); 

     // new connection opened callback 
     source.addEventListener('open', function(e) { 
      console.log('connection opened'); 
     }, false); 

     // new connection opened callback 
     source.addEventListener('message', function(e) { 
      console.log(e.data); 
      msg = JSON.parse(e.data); 
      $('#result').append('<br/>').append(msg); 
     }, false); 

     // connection closed callback 
     source.addEventListener('error', function(e) { 
      if (e.eventPhase == EventSource.CLOSED) { 
      console.log('connection closed'); 
      } 
     }, false); 
    } else { 
     $('#result').append('<br/>').append("Whoops! Your browser doesn't receive server-sent events.") ; 
    } 
    </script> 

巨人成分

#!/usr/bin/env ruby 
require 'rubygems' 
require 'goliath' 

class RedisPubsub < Goliath::API 
    use(Rack::Static, :root => Goliath::Application.app_path("public"), :urls => ["/index.html", "/twitter.html", "/favicon.ico", '/stylesheets/', '/javascripts/', '/images/']) 
    use Goliath::Rack::Params 
    use Goliath::Rack::Render, 'json' 

    def response(env) 
    ... 
    .... 
    env.stream_send("data:#{message}\n\n") 
    streaming_response(200, {'Content-Type' => 'text/event-stream', 'Access-Control-Allow-Origin' => '*'}) 
    end 
end 

歌利亞流媒體服務器是在本地機器上的9000端口上運行。當我嘗試通過http://localhost/index.html訪問該頁面時,即使它發送CORS的「訪問控制 - 允許 - 來源」標題作爲響應,它也會提供Chrome中提到的錯誤。請不要在這裏工作正常FF。

任何想法如何解決這個問題?

回答

相關問題