From 8c4ec9bfd003a923ca8217b056b957ece532ebdd Mon Sep 17 00:00:00 2001 From: nickbrowne Date: Wed, 22 Oct 2025 15:10:42 +1100 Subject: [PATCH 1/5] Add a demo server script backed by postgres --- bin/exampleserver-pg | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 bin/exampleserver-pg diff --git a/bin/exampleserver-pg b/bin/exampleserver-pg new file mode 100755 index 0000000..4587507 --- /dev/null +++ b/bin/exampleserver-pg @@ -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); +}); From f8ca362313b5408b2df39e6f619dc47c192b010b Mon Sep 17 00:00:00 2001 From: nickbrowne Date: Wed, 22 Oct 2025 15:11:24 +1100 Subject: [PATCH 2/5] Mention the fact the regular demo server is memory backed only --- bin/exampleserver | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/exampleserver b/bin/exampleserver index f5dfc7d..4bb6894 100755 --- a/bin/exampleserver +++ b/bin/exampleserver @@ -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; From 49a3765f2de2a4f4e5fab64eefb4a22a3b7f6a9e Mon Sep 17 00:00:00 2001 From: nickbrowne Date: Wed, 22 Oct 2025 15:12:41 +1100 Subject: [PATCH 3/5] Rename exampleserver to demoserver to better reflect the purpose --- bin/{exampleserver => demoserver} | 0 bin/{exampleserver-pg => demoserver-pg} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename bin/{exampleserver => demoserver} (100%) rename bin/{exampleserver-pg => demoserver-pg} (100%) diff --git a/bin/exampleserver b/bin/demoserver similarity index 100% rename from bin/exampleserver rename to bin/demoserver diff --git a/bin/exampleserver-pg b/bin/demoserver-pg similarity index 100% rename from bin/exampleserver-pg rename to bin/demoserver-pg From 4ccd82bd8cbed1a3493dd0badfcea2aa87f5d69a Mon Sep 17 00:00:00 2001 From: nickbrowne Date: Wed, 22 Oct 2025 15:13:09 +1100 Subject: [PATCH 4/5] Update READMEs to reflect some renamed files --- README.md | 24 +++++++++++------------- examples/README.md | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d6cd7c6..75e8c70 100644 --- a/README.md +++ b/README.md @@ -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`. @@ -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. @@ -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 -------------------------------- diff --git a/examples/README.md b/examples/README.md index dcaf7b9..3b0dd00 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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 From 922b03e262ec05606ceb450ceecd208820efe061 Mon Sep 17 00:00:00 2001 From: nickbrowne Date: Wed, 22 Oct 2025 15:15:35 +1100 Subject: [PATCH 5/5] Remove old exampleserver bin from package.json --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index bf83430..0f467bb 100644 --- a/package.json +++ b/package.json @@ -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",