2013-03-10 102 views
1

我正在嘗試使用Sharejs進行協作式文本編輯器,但我一開始就遇到了一些問題。ShareJS示例不起作用

我從「入門」頁面開始。我運行npm install share,然後使用./node_modules/share/bin/exampleserver運行示例服務器。這工作正常。

然後,我嘗試按照「運行服務器」部分中的步驟創建我自己的小應用程序。我寫的app.js文件和建議的HTML,當我試圖運行此,對瀏覽器控制檯404錯誤說,它無法找到socket.io.js:

GET http://localhost:8000/socket.io/socket.io.js 404 (Not Found) 

,然後我得到這個錯誤一再:

GET http://localhost:8000/test?VER=8&MODE=init&zx=ktil5643g6cw&t=1 404 (Not Found) 

有誰知道是什麼原因造成這種任何建議或想法?我知道它可以工作,因爲預先配置的示例在本地很有用,正如我前面提到的,這只是當我嘗試創建新應用程序時,我一定不能配置正確的東西。

謝謝。

+0

你有沒有得到這個解決了嗎?我有同樣的問題,下面的答案並沒有解決我 – jonnie 2014-10-14 13:14:33

回答

4

我更新日誌,你可以看到以下內容:

client.open('hello', 'text', function(doc, error) { 
    // ... 
}); 

成爲

client.open('hello', 'text', function(error, doc) { 
    // ... 
}); 

例仍然包含過時的回調function(doc, error)。此外,請將客戶端上的URL更改爲http://example.com:8000/channel

在我的情況下最終版本是:

服務器

var connect = require('./node_modules/connect'), 
    sharejs = require('./node_modules/share').server; 

var server = connect(
    connect.logger(), 
    connect.static(__dirname + '/public') 
); 
var options = {db:{type:'none'}}; // See docs for options. {type: 'redis'} to enable persistance. 

// Attach the sharejs REST and Socket.io interfaces to the server 
sharejs.attach(server, options); 

server.listen(8000, function() { 
    console.log('Server running at http://127.0.0.1:8000/'); 
}); 

CLIENT

<!DOCTYPE html> 
<html> 
<head> 
    <title>Test</title> 
    <script src="http://ajaxorg.github.com/ace/build/src/ace.js"></script> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
    <script src="/channel/bcsocket.js"></script> 
    <script src="/share/share.js"></script> 
    <script src="/share/ace.js"></script> 
    <script> 
     $(document).ready(function() { 
      var editor = ace.edit("editor"); 

      sharejs.open('hello', 'text', 'http://localhost:8000/channel', function (error, doc) { 
       doc.attach_ace(editor); 
      }); 
     }); 
    </script> 
    <style> 
     #editor { 
      width: 200px; 
      height: 100px; 
     } 
    </style> 
</head> 
<body> 
<div id="editor"></div> 
</body> 
</html> 
+0

服務器需要是node.js還是可以使用IIS作爲服務器? – AFetter 2013-11-10 11:17:50

+2

ShareJS是NodeJS和瀏覽器的操作變換庫。 – Marboni 2013-11-11 05:16:47