2013-03-10 100 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