Sharejs未在客户端加载

时间:2014-03-06 14:22:01

标签: node.js express socket.io share.js

服务器

var express = require('express');
var app = express();
var connect = require('connect');
var sharejs = require('share').server;
var server = connect(
  connect.static(__dirname + '/public/client/')
  );
var options = {db: {type: 'none'}};
sharejs.attach(server, options);

**var server = http.createServer(app).listen(app.get('port'), function(){
});**

客户端

<script src="/channel/bcsocket.js"></script>
<script src="/client/share/share.js"></script>
<script src="/share/ace.js"></script>

错误

**GET http://localhost:3000/channel/bcsocket.js 404 (Not Found)**

**GET http://localhost:3000/share/share.js 404 (Not Found)**

**GET http://localhost:3000/share/ace.js 404 (Not Found)**

我无法连接到客户端和服务器。我无法弄清楚出了什么问题

1 个答案:

答案 0 :(得分:0)

看起来无法找到脚本。

如果server.js位于 myapp / server.js 中, 以下

connect.static(__dirname + '/public/client/')

将从 myapp / public / client / 文件夹中提供静态文件。

因此,如果share.js文件位于 myapp / public / client / share / share.js 中,则在client.html中您将拥有

<script src="/share/share.js"></script>

此外,您应该将服务器配置为侦听

var connect = require('connect');
var sharejs = require('share').server;
var server = connect(
      connect.static(__dirname + '/public/client/')
  );
var options = {db: {type: 'none'}};
sharejs.attach(server, options);

/** configure the server to listen on a port **/
server.listen(3000);