我正在尝试为DokuWiki开发一个插件,该插件将使 wiki 页面的实时协作编辑成为可能。我正在使用Node.js和ShareJS这样做,但我遇到了一些麻烦,因为这是我第一次使用它们......
ShareJS 服务器 - http://localhost:3000
var express = require('express');
var app = express();
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', 'http://localhost:3000');
res.header('Access-Control-Allow-Methods', 'GET, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.header('Access-Control-Allow-Credentials', true);
return next();
});
// public folder to store assets
app.use(express.static(__dirname + '/public'));
// get sharejs dependencies
var sharejs = require('share');
require('redis');
// options for sharejs
var options = {
db: {type: 'redis'},
browserChannel: { cors: "http://localhost/dokuwiki/" },
};
// attach the express server to sharejs
sharejs.server.attach(app, options);
// listen on port 3000 (for localhost) or the port defined for heroku
var port = process.env.PORT || 3000;
app.listen(port);
顺便说一句,当我运行它时会输出此警告:
多库维基
例如,在编辑 wiki 页面时,http://localhost/dokuwiki/doku.php?id=start&do=edit
插件包含以下脚本:
- http://localhost:3000/channel/bcsocket.js
- http://localhost:3000/share/share.js
- http://localhost:3000/share/textarea.js
然后执行这个:
window.onload = function() {
// get dokuwiki editor textarea element
var pad = document.getElementById('wiki__text');
if (pad) { // if a wiki page is being edited
// Server options
var options = {
origin: "http://localhost:3000/channel"
};
// Connect to the server
var connection = sharejs.open('test', 'text', options, function(error, doc) {
doc.attach_textarea(pad);
});
}
};
这导致 DokuWiki 页面编辑器出现以下错误:
我错过了什么?提前致谢!