Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ Install required packages, and compile the web client code:

npm install

Run the simple example server which includes basic clients with:
Run the simple example server with demos which uses a non-persistent memory store:

./bin/exampleserver
./bin/demoserver

Run a standalone example server by first creating a postgres database, then running the example server itself:
There's also an example with demos that persists the data to postgres:

./bin/demoserver-pg

And finally a standalone example server without the demos.

First create a postgres database, then the server:

createdb sharejs_example
./bin/sharejs

See `bin/options.js` for how to configure the example server.
See `bin/options.js` for how to configure the standalone example server.

If you need to re-compile the web client code, just run `npm install` again, or alternatively you can use `npm run prepublish`.

Expand Down Expand Up @@ -70,7 +76,7 @@ There are two ways to run a sharejs server:
server.listen(9000);
console.log('Server running at http://127.0.0.1:9000/');
```
The above script will start up a ShareJS server on port 9000 which hosts static content from the `my_html_files` directory. See [bin/exampleserver](https://github.com/josephg/ShareJS/blob/master/bin/exampleserver) for a more complex configuration example.
The above script will start up a ShareJS server on port 9000 which hosts static content from the `my_html_files` directory. See [bin/demoserver](https://github.com/conversation/ShareJS/blob/master/bin/demoserver) for a more complex configuration example.

> See the [Express](http://expressjs.com/) documentation for more complex routing.

Expand All @@ -79,14 +85,6 @@ There are two ways to run a sharejs server:
# sharejs
Configuration is pulled from a configuration file that can't be easily edited at the moment. For now, I recommend method #1 above.

3. If you are just mucking around, run:

# sharejs-exampleserver

This will run a simple server on port 8000, and host all the example code there. Run it and check out http://localhost:8000/ . The example server stores everything in ram, so don't get too attached to your data.

> If you're running sharejs from source, you can launch the example server by running `bin/exampleserver`.


Putting Share.js on your website
--------------------------------
Expand Down
2 changes: 1 addition & 1 deletion bin/exampleserver → bin/demoserver
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var options = {
}
};

console.log("ShareJS example server v" + sharejs.version);
console.log("ShareJS example server v" + sharejs.version + " using memory store");
console.log("Options: ", options);

var port = argv.p;
Expand Down
74 changes: 74 additions & 0 deletions bin/demoserver-pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env node

// This is a simple example sharejs server which hosts the sharejs
// examples in examples/.
//
// It demonstrates a few techniques to get different application behaviour.

require('coffee-script');
var express = require('express'),
sharejs = require('../src'),
hat = require('hat').rack(32, 36);

var argv = require('optimist').
usage("Usage: $0 [-p portnum]").
default('p', 8000).
alias('p', 'port').
argv;

var app = express();
app.use(express.static(__dirname + '/../examples'));

var options = {
db: {
type: 'pg',
schema: 'public',
operations_table: 'operations',
snapshot_table: 'snapshots',
connectionString: process.platform == "darwin" ? "/tmp" : "/var/run/postgresql",
create_tables_automatically: true
},
websocket: {
prefix: '/websocket',
trackStats: function(stats) {
console.log("Tracking stats:", JSON.stringify(stats));
}
},
auth: function(client, action) {
// This auth handler rejects any ops bound for docs starting with 'readonly'.
if (action.name === 'submit op' && action.docName.match(/^readonly/)) {
action.reject();
} else {
action.accept();
}
}
};

console.log("ShareJS example server v" + sharejs.version + " using postgres");
console.log("Options: ", options);

var port = argv.p;

// Attach the sharejs REST and websocket interfaces to the server
var server = sharejs.server.attach(app, options);

app.get('/pad/?', function(req, res, next) {
var docName;
docName = hat();
res.writeHead(303, {location: '/pad/pad.html#' + docName});
res.write('');
res.end();
});

app.get('/?', function(req, res, next) {
res.writeHead(302, {location: '/index.html'});
res.end();
});
server.listen(port);
console.log("Demos running at http://localhost:" + port);

process.title = 'sharejs'
process.on('uncaughtException', function (err) {
console.error('An error has occurred. Please file a ticket here: https://github.com/josephg/ShareJS/issues');
console.error('Version ' + sharejs.version + ': ' + err.stack);
});
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ This is a bunch of little demo apps using Share.js.

Launch the example sharejs server with

% bin/exampleserver
% bin/demoserver


readonly
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"engine": "node >= 0.6",
"main": "index.js",
"bin": {
"sharejs": "bin/sharejs",
"sharejs-exampleserver": "bin/exampleserver"
"sharejs": "bin/sharejs"
},
"scripts": {
"build": "cake build",
Expand Down