From ae6114931dc731ea7be72c886753890472ad4a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geir=20G=C3=A5sodden?= Date: Wed, 17 Jan 2018 09:08:50 +0100 Subject: [PATCH] Adds concurrently. Updates README (patch) --- README.md | 38 ++++++++---------------- gun-servers/server-gun-restricted-put.js | 2 +- gun-servers/server-gun-unrestricted.js | 2 +- package.json | 8 ++--- test/modules/dependencies-test.js | 2 +- www/server.js | 3 +- 6 files changed, 20 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 7017eb4..a2e6550 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # gun-restrict-examples -Examples of how to restrict put and get with [GUN](https://github.com/amark/gun) +Example of how to restrict put with [GUN](https://github.com/amark/gun) The solutions are based on an answer from [stackoverflow](https://stackoverflow.com/questions/38598391/jwt-authentication-with-gundb) @@ -10,43 +10,31 @@ Clone or download the repo. cd into directory and run ```npm install``` -Now open 3 terminals and follow the instructions +## Restricted put example -### Terminal 1 - -Start the gun server with restricted put - -```bash -$ npm run restricted-put -``` - -This will start the server at localhost port 8000 - -### Terminal 2 - -Start the webserver for authenticated site +Open a terminal and start the services ```bash $ npm start ``` -Visit [http://localhost:3000](http://localhost:3000) -### Terminal 3 +This will start 3 servers +- The GUN server at localhost port 8000 +- The authenticated site on localhost port 3000 +- The unauthenticated site on localhost port 4000 -Start the webserver for authenticated +Open 2 browsers. +- Visit [http://localhost:3000](http://localhost:3000) in one +- Visit [http://localhost:4000](http://localhost:4000) in the other -```bash -$ npm run start-unauth -``` -Visit [http://localhost:4000](http://localhost:4000) in another browser - -## What to expect +### What to expect Everything you write on the authenticated site will be synced to the unathenticated, but not the other way around. ## Explore more -If you want to se GUN in action without restrictions stop your localhost:8000 by going to terminal # 1 and pressing CTRL + C. +If you want to se GUN in action without restrictions stop the running service pressing CTRL + C in the terminal. + Start an unrestricted GUN server. ```bash diff --git a/gun-servers/server-gun-restricted-put.js b/gun-servers/server-gun-restricted-put.js index 786d279..41bd610 100644 --- a/gun-servers/server-gun-restricted-put.js +++ b/gun-servers/server-gun-restricted-put.js @@ -51,5 +51,5 @@ gun.on('out', {get: {'#': {'*': ''}}}) server.listen(port) -console.log('Server started on port 8000') +console.log('GUN server (restricted put) started on port 8000') console.log('Use CTRL + C to stop it') diff --git a/gun-servers/server-gun-unrestricted.js b/gun-servers/server-gun-unrestricted.js index 4d84c09..9595a0a 100644 --- a/gun-servers/server-gun-unrestricted.js +++ b/gun-servers/server-gun-unrestricted.js @@ -25,5 +25,5 @@ gun.on('out', {get: {'#': {'*': ''}}}) server.listen(port) -console.log('Unrestricted server started on port ' + port + ' with /gun') +console.log('GUN server (unrestricted) started on port 8000') console.log('Use CTRL + C to stop it') diff --git a/package.json b/package.json index 803a1b5..9dfad86 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,8 @@ "main": "index.js", "scripts": { "test": "nsp check && standard && ava", - "restricted-put": "node gun-servers/server-gun-restricted-put", - "unrestricted": "node gun-servers/server-gun-unrestricted", - "restricted": "node gun-servers/server-gun-restricted", - "start": "node www/server", - "start-unauth": "node www/server 4000 not-authenticated.html", + "unrestricted": "concurrently -k \"node www/server\" \"node gun-servers/server-gun-unrestricted\" \"node www/server 4000 not-authenticated.html\"", + "start": "concurrently -k \"node www/server\" \"node gun-servers/server-gun-restricted-put\" \"node www/server 4000 not-authenticated.html\"", "refresh": "rm -rf node_modules && rm package-lock.json && npm install" }, "standard": { @@ -29,6 +26,7 @@ }, "homepage": "https://github.com/zrrrzzt/gun-restrict-examples#readme", "dependencies": { + "concurrently": "3.5.1", "finalhandler": "1.1.0", "gun": "0.9.8", "serve-static": "1.13.1" diff --git a/test/modules/dependencies-test.js b/test/modules/dependencies-test.js index 0929c9a..3becebc 100644 --- a/test/modules/dependencies-test.js +++ b/test/modules/dependencies-test.js @@ -1,7 +1,7 @@ const test = require('ava') const pkg = require('../../package.json') const dependencies = pkg.dependencies || {} -const dropModules = ['gun'] +const dropModules = ['gun', 'concurrently'] const isDropped = (module) => !dropModules.includes(module) if (Object.keys(dependencies).length > 0) { diff --git a/www/server.js b/www/server.js index f32bb3b..6a687c7 100644 --- a/www/server.js +++ b/www/server.js @@ -14,5 +14,4 @@ const server = http.createServer(function onRequest (req, res) { // Listen server.listen(port) -console.log(`server started on port: ${port}`) -console.log('Use CTRL + C to stop it') +console.log(`www server started on port: ${port} - ${index}`)