From 28228c5cc4cacaec357ef66fcd4af1dd68e1bd85 Mon Sep 17 00:00:00 2001 From: cubedro Date: Thu, 26 Feb 2015 23:45:24 +0200 Subject: [PATCH 1/2] added websockets login --- README.md | 21 +++++++++++---------- bin/build.sh | 2 +- lib/node.js | 4 ++-- processes.json | 9 ++++++--- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 28626c4..70d086c 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,9 @@ Fetch and run the build shell. This will install everything you need: latest cpp curl https://raw.githubusercontent.com/cubedro/eth-net-intelligence-api/master/bin/build.sh | sh ``` -## Run - -Run it using pm2: - -``` -cd ~/bin/www -pm2 start processes.json -``` - ## Configuration -Configure the app in [processes.json](/eth-net-intelligence-api/blob/master/processes.json) +Configure the app modifying [processes.json](/eth-net-intelligence-api/blob/master/processes.json). Note that you have to modify the backup processes.json file located in `./bin/processes.json` (to allow you to set your env vars without being rewritten when updating). ``` "env": @@ -38,9 +29,19 @@ Configure the app in [processes.json](/eth-net-intelligence-api/blob/master/proc "RPC_HOST" : "localhost", // eth JSON-RPC host "RPC_PORT" : "8080", // eth JSON-RPC port "WS_SERVER" : "", // path to eth-netstats WebSockets api server + "WS_SECRET" : "", // WebSockets api server secret used for login } ``` +## Run + +Run it using pm2: + +``` +cd ~/bin +pm2 start processes.json +``` + [travis-image]: https://travis-ci.org/cubedro/eth-net-intelligence-api.svg [travis-url]: https://travis-ci.org/cubedro/eth-net-intelligence-api [dep-image]: https://david-dm.org/cubedro/eth-net-intelligence-api.svg diff --git a/bin/build.sh b/bin/build.sh index 7dc3a68..ea64f6a 100644 --- a/bin/build.sh +++ b/bin/build.sh @@ -54,4 +54,4 @@ cd www sudo npm install sudo npm install pm2 -g -pm2 start processes.json +cp -b ./processes.json ./.. diff --git a/lib/node.js b/lib/node.js index a72a584..c7d4a49 100644 --- a/lib/node.js +++ b/lib/node.js @@ -74,7 +74,7 @@ function Node() web3.setProvider(new web3.providers.HttpSyncProvider('http://' + (process.env.RPC_HOST || 'localhost') + ':' + (process.env.RPC_PORT || '8080'))); socket.on('open', function open() { - socket.emit('hello', { id: self.id, info: self.info}); + socket.emit('hello', { id: self.id, info: self.info, secret: process.env.WS_SECRET }); console.log('The connection has been opened.'); }).on('end', function end() { self._socket = false; @@ -92,7 +92,7 @@ function Node() self.sendUpdate(true); console.log('The connection has been established.'); - }) + }); this.init(); diff --git a/processes.json b/processes.json index 2b30965..c75449d 100644 --- a/processes.json +++ b/processes.json @@ -1,7 +1,8 @@ [ { "name" : "eth", - "script" : "./bin/eth.sh", + "cwd" : "/home/ubuntu/bin/www/", + "script" : "bin/eth.sh", "log_file" : "/home/ubuntu/logs/eth-log.log", "out_file" : "/home/ubuntu/logs/eth-out.log", "error_file" : "/home/ubuntu/logs/eth-err.log", @@ -13,7 +14,8 @@ }, { "name" : "node-app", - "script" : "./app.js", + "cwd" : "/home/ubuntu/bin/www/", + "script" : "app.js", "log_file" : "/home/ubuntu/logs/node-app-log.log", "out_file" : "/home/ubuntu/logs/node-app-out.log", "error_file" : "/home/ubuntu/logs/node-app-err.log", @@ -27,7 +29,8 @@ "NODE_ENV" : "production", "RPC_HOST" : "localhost", "RPC_PORT" : "8080", - "WS_SERVER" : "wss://eth-netstats.herokuapp.com", + "WS_SERVER" : "", + "WS_SECRET" : "", } } ] \ No newline at end of file From fb983ed0e7a228f59cfe980500044dc28a8fda7a Mon Sep 17 00:00:00 2001 From: cubedro Date: Thu, 26 Feb 2015 23:47:56 +0200 Subject: [PATCH 2/2] added update in readme.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 70d086c..03aaad0 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,20 @@ cd ~/bin pm2 start processes.json ``` +## Updating + +To update the API client use the following commands: + +``` +pm2 kill +cd ~/bin/www +git pull +sudo npm update +sudo npm install +cd .. +pm2 start processes.json +``` + [travis-image]: https://travis-ci.org/cubedro/eth-net-intelligence-api.svg [travis-url]: https://travis-ci.org/cubedro/eth-net-intelligence-api [dep-image]: https://david-dm.org/cubedro/eth-net-intelligence-api.svg