1

Server Side code,

var express = require('express'); //Web Framework
var app = express();
var http = require('http').Server(app); //HTTP server module
var connect = require('connect'),
    sharejs = require('share').server;

app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});


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);

app.get('/', function (req, res) {
  res.sendFile('index.html', { root: __dirname });
})


http.listen(3000, function () {
    console.log('listening on *:3000');
});

But I cant get the share.js to work.

It gives an error, ReferenceError: server is not defined

How do I get express to work along with share.js?

Kevin Desai
  • 317
  • 3
  • 22

1 Answers1

0

ShareJS 0.6

If you're using ShareJS 0.6, the issue is that you're using require('share').http instead of require('share').server.

Change:

var connect = require('connect'),
    sharejs = require('share').http;

To:

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

ShareJS 0.7

If you're using ShareJS 0.7, the attach method has been deprecated. See this answer for a workaround.


Update

Now that your answer has been updated, the problem is that you haven't defined the server variable. The documentation states that you can define this using:

var server = connect(
      connect.logger(),
      connect.static(__dirname + '/public')
    );
Community
  • 1
  • 1
James Donnelly
  • 126,410
  • 34
  • 208
  • 218
  • Changed it to server. Using 0.6.3, not working, give this error, TypeError: Object # has no method 'use' – Kevin Desai Dec 20 '14 at 13:42
  • No, still doesn't work. TypeError: Object function createServer() { function app(req, res, next){ app.handle(req, res, next); } merge(app, proto); merge(app, EventEmitter.prototype); app.route = '/'; app.stack = []; return app; } has no method 'logger' Express with share really seems to be like an issue – Kevin Desai Dec 20 '14 at 14:03
  • @KevinDesai in that case I don't think I'm able to help further. Might be worth raising this as an issue on ShareJS's GitHub repository: https://github.com/share/ShareJS. – James Donnelly Dec 20 '14 at 14:05