From bdecda99baa44aa007b18d3483f3ff6be26a3394 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Tue, 6 Nov 2018 10:19:49 +0100 Subject: [PATCH] Added UI as submodule and as static in production, changed endpoint to /api/graphql --- .gitmodules | 3 + apolloui | 1 + config/production.json | 1 + miner-test-server.js | 350 +++++++++++++++++++++-------------------- src/app/app.js | 6 +- 5 files changed, 190 insertions(+), 171 deletions(-) create mode 100644 .gitmodules create mode 160000 apolloui create mode 100644 config/production.json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..73e374b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "apolloui"] + path = apolloui + url = https://github.com/CryptofyCH/apolloui diff --git a/apolloui b/apolloui new file mode 160000 index 0000000..95ae5ac --- /dev/null +++ b/apolloui @@ -0,0 +1 @@ +Subproject commit 95ae5ac443284b49fd81d94a396de340d8d7280f diff --git a/config/production.json b/config/production.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/config/production.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/miner-test-server.js b/miner-test-server.js index ca455eb..6e43886 100644 --- a/miner-test-server.js +++ b/miner-test-server.js @@ -1,179 +1,189 @@ 'use strict'; -const sampleData = { - "summary": [ - { - "STATUS": [ - { - "STATUS": "S", - "When": 1541144892, - "Code": 11, - "Msg": "Summary", - "Description": "bfgminer 5.4.2" - } - ], - "SUMMARY": [ - { - "Elapsed": 847, - "MHS av": 3.364, - "MHS 20s": 3.324, - "Found Blocks": 0, - "Getworks": 30, - "Accepted": 168, - "Rejected": 0, - "Hardware Errors": 2, - "Utility": 11.9, - "Discarded": 78, - "Stale": 0, - "Get Failures": 0, - "Local Work": 138, - "Remote Failures": 0, - "Network Blocks": 5, - "Total MH": 2849.3488, - "Diff1 Work": 0.67822266, - "Work Utility": 0.048, - "Difficulty Accepted": 0.65625, - "Difficulty Rejected": 0, - "Difficulty Stale": 0, - "Best Share": 1.03726997, - "Device Hardware%": 0.1438, - "Device Rejected%": 0, - "Pool Rejected%": 0, - "Pool Stale%": 0, - "Last getwork": 1541144888 - } - ], - "id": 1 - } - ], - "devs": [ - { - "STATUS": [ - { - "STATUS": "S", - "When": 1541144892, - "Code": 9, - "Msg": "1 PGA(s)", - "Description": "bfgminer 5.4.2" - } - ], - "DEVS": [ - { - "PGA": 0, - "Name": "MLD", - "ID": 0, - "Enabled": "Y", - "Status": "Alive", - "Device Elapsed": 847, - "MHS av": 3.363, - "MHS 20s": 3.373, - "MHS rolling": 3.373, - "Accepted": 168, - "Rejected": 0, - "Hardware Errors": 2, - "Utility": 11.897, - "Stale": 0, - "Last Share Pool": 1, - "Last Share Time": 1541144887, - "Total MH": 2849.3488, - "Diff1 Work": 0.67822266, - "Work Utility": 0.048, - "Difficulty Accepted": 0.65625, - "Difficulty Rejected": 0, - "Difficulty Stale": 0, - "Last Share Difficulty": 0.00390625, - "Last Valid Work": 1541144891, - "Device Hardware%": 0.1438, - "Device Rejected%": 0 - } - ], - "id": 1 - } - ], - "pools": [ - { - "STATUS": [ - { - "STATUS": "S", - "When": 1541144892, - "Code": 7, - "Msg": "2 Pool(s)", - "Description": "bfgminer 5.4.2" - } - ], - "POOLS": [ - { - "POOL": 0, - "URL": "stratum+tcp://us.litecoinpool.org:3333", - "Status": "Alive", - "Priority": 1, - "Quota": 1, - "Mining Goal": "default", - "Long Poll": "N", - "Getworks": 3, - "Accepted": 0, - "Rejected": 0, - "Works": 0, - "Discarded": 0, - "Stale": 0, - "Get Failures": 0, - "Remote Failures": 0, - "User": "jstefanop.1", - "Last Share Time": 0, - "Diff1 Shares": 0, - "Proxy": "", - "Difficulty Accepted": 0, - "Difficulty Rejected": 0, - "Difficulty Stale": 0, - "Last Share Difficulty": 0, - "Has Stratum": true, - "Stratum Active": false, - "Stratum URL": "", - "Best Share": 0, - "Pool Rejected%": 0, - "Pool Stale%": 0 - }, - { - "POOL": 1, - "URL": "stratum+tcp://us.litecoinpool.org:3333", - "Status": "Alive", - "Priority": 0, - "Quota": 1, - "Mining Goal": "default", - "Long Poll": "N", - "Getworks": 27, - "Accepted": 168, - "Rejected": 0, - "Works": 30, - "Discarded": 78, - "Stale": 0, - "Get Failures": 0, - "Remote Failures": 0, - "User": "jstefanop.1", - "Last Share Time": 1541144887, - "Diff1 Shares": 0.67822266, - "Proxy": "", - "Difficulty Accepted": 0.65625, - "Difficulty Rejected": 0, - "Difficulty Stale": 0, - "Last Share Difficulty": 0.00390625, - "Has Stratum": true, - "Stratum Active": true, - "Stratum URL": "us.litecoinpool.org", - "Best Share": 1.03726997, - "Pool Rejected%": 0, - "Pool Stale%": 0 - } - ], - "id": 1 - } - ], - "id": 1 +function getData() { + return { + "summary": [ + { + "STATUS": [ + { + "STATUS": "S", + "When": 1541144892, + "Code": 11, + "Msg": "Summary", + "Description": "bfgminer 5.4.2" + } + ], + "SUMMARY": [ + { + "Elapsed": 847, + "MHS av": getRandomFloat(3.00, 4.00), + "MHS 20s": 3.324, + "Found Blocks": 0, + "Getworks": 30, + "Accepted": 168, + "Rejected": 0, + "Hardware Errors": 2, + "Utility": 11.9, + "Discarded": 78, + "Stale": 0, + "Get Failures": 0, + "Local Work": 138, + "Remote Failures": 0, + "Network Blocks": 5, + "Total MH": 2849.3488, + "Diff1 Work": 0.67822266, + "Work Utility": 0.048, + "Difficulty Accepted": 0.65625, + "Difficulty Rejected": 0, + "Difficulty Stale": 0, + "Best Share": 1.03726997, + "Device Hardware%": 0.1438, + "Device Rejected%": 0, + "Pool Rejected%": 0, + "Pool Stale%": 0, + "Last getwork": 1541144888 + } + ], + "id": 1 + } + ], + "devs": [ + { + "STATUS": [ + { + "STATUS": "S", + "When": 1541144892, + "Code": 9, + "Msg": "1 PGA(s)", + "Description": "bfgminer 5.4.2" + } + ], + "DEVS": [ + { + "PGA": 0, + "Name": "MLD", + "ID": 0, + "Enabled": "Y", + "Status": "Alive", + "Device Elapsed": 847, + "MHS av": 3.363, + "MHS 20s": 3.373, + "MHS rolling": 3.373, + "Accepted": 168, + "Rejected": 0, + "Hardware Errors": 2, + "Utility": 11.897, + "Stale": 0, + "Last Share Pool": 1, + "Last Share Time": 1541144887, + "Total MH": 2849.3488, + "Diff1 Work": 0.67822266, + "Work Utility": 0.048, + "Difficulty Accepted": 0.65625, + "Difficulty Rejected": 0, + "Difficulty Stale": 0, + "Last Share Difficulty": 0.00390625, + "Last Valid Work": 1541144891, + "Device Hardware%": 0.1438, + "Device Rejected%": 0 + } + ], + "id": 1 + } + ], + "pools": [ + { + "STATUS": [ + { + "STATUS": "S", + "When": 1541144892, + "Code": 7, + "Msg": "2 Pool(s)", + "Description": "bfgminer 5.4.2" + } + ], + "POOLS": [ + { + "POOL": 0, + "URL": "stratum+tcp://us.litecoinpool.org:3333", + "Status": "Alive", + "Priority": 1, + "Quota": 1, + "Mining Goal": "default", + "Long Poll": "N", + "Getworks": 3, + "Accepted": 0, + "Rejected": 0, + "Works": 0, + "Discarded": 0, + "Stale": 0, + "Get Failures": 0, + "Remote Failures": 0, + "User": "jstefanop.1", + "Last Share Time": 0, + "Diff1 Shares": 0, + "Proxy": "", + "Difficulty Accepted": 0, + "Difficulty Rejected": 0, + "Difficulty Stale": 0, + "Last Share Difficulty": 0, + "Has Stratum": true, + "Stratum Active": false, + "Stratum URL": "", + "Best Share": 0, + "Pool Rejected%": 0, + "Pool Stale%": 0 + }, + { + "POOL": 1, + "URL": "stratum+tcp://us.litecoinpool.org:3333", + "Status": "Alive", + "Priority": 0, + "Quota": 1, + "Mining Goal": "default", + "Long Poll": "N", + "Getworks": 27, + "Accepted": 168, + "Rejected": 0, + "Works": 30, + "Discarded": 78, + "Stale": 0, + "Get Failures": 0, + "Remote Failures": 0, + "User": "jstefanop.1", + "Last Share Time": 1541144887, + "Diff1 Shares": 0.67822266, + "Proxy": "", + "Difficulty Accepted": 0.65625, + "Difficulty Rejected": 0, + "Difficulty Stale": 0, + "Last Share Difficulty": 0.00390625, + "Has Stratum": true, + "Stratum Active": true, + "Stratum URL": "us.litecoinpool.org", + "Best Share": 1.03726997, + "Pool Rejected%": 0, + "Pool Stale%": 0 + } + ], + "id": 1 + } + ], + "id": 1 + } } const net = require('net'); const PORT = 4028; const HOST = 'localhost'; + +function getRandomArbitrary(min, max) { + return Math.random() * (max - min) + min; +} + +function getRandomFloat(min, max) { + return parseFloat(Math.random() * (max - min) + min); +} class Server { constructor(port, address) { @@ -193,7 +203,7 @@ class Server { sock.on('data', (data) => { console.log(`${clientName} Says: ${data}`); - sock.write(JSON.stringify(sampleData)); + sock.write(JSON.stringify(getData())); // sock.write('exit'); }); diff --git a/src/app/app.js b/src/app/app.js index 2717a63..8c616f9 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -1,9 +1,13 @@ +const path = require('path') const express = require('express') const config = require('config') const graphqlApp = require('./graphqlApp') +const buildPath = path.join(__dirname, '../../apolloui/build'); const app = express() -app.use('/graphql', graphqlApp) +app.use('/api/graphql', graphqlApp) + +if (process.env.NODE_ENV === 'production') app.use(express.static(buildPath)); module.exports = app