我正在尝试使用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) 有没有人有任何建议或想法,是什么导致了这一切?我知道它可以工作,因为预配置的示例在本地工作很好,正如我前面提到的,只是当我试图创建一个新的应用程序时,我必须不能正确地配置一些东西。
谢谢。
发布于 2013-04-17 05:52:04
你可以看到下面的变化:
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/');
});客户端
<!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>https://stackoverflow.com/questions/15318935
复制相似问题