From 3fd093041e1ffe59187a267fc28eb9015c14a62d Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Tue, 6 Jun 2017 18:32:15 +0200 Subject: [PATCH] added experimental shepherd cli route --- main.js | 4 ++-- routes/shepherd.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index d986083..e04a766 100644 --- a/main.js +++ b/main.js @@ -298,10 +298,10 @@ function createWindow (status) { if (appConfig.edexGuiOnly) { if (appConfig.v2) { shepherd.writeLog('show edex gui'); - //mainWindow.loadURL('http://127.0.0.1:3000'); + mainWindow.loadURL('http://127.0.0.1:3000'); mainWindow.appConfig = appConfig; mainWindow.appSessionHash = appSessionHash; - mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.agamaPort + '/gui/EasyDEX-GUI/react/build'); + // mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.agamaPort + '/gui/EasyDEX-GUI/react/build'); } else { shepherd.writeLog('show edex gui'); mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.agamaPort + '/gui/EasyDEX-GUI/'); diff --git a/routes/shepherd.js b/routes/shepherd.js index 9cfc851..65b9014 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -280,6 +280,50 @@ shepherd.quitKomodod = function(chain) { }); } +/* + * type: POST + * params: payload + */ +shepherd.post('/cli', function(req, res, next) { + if (!req.body.payload) { + const errorObj = { + 'msg': 'error', + 'result': 'no payload provided' + }; + + res.end(JSON.stringify(errorObj)); + } else { + const _mode = req.body.payload.mode === 'passthru' ? 'passthru' : 'default'; + const _chain = req.body.payload.chain ? req.body.payload.chain : ''; + const _cmd = req.body.payload.cmd; + + exec(komodocliBin + (_chain ? ' ac_name=' + _chain : '') + ' ' + _cmd, function(error, stdout, stderr) { + console.log('stdout: ' + stdout) + console.log('stderr: ' + stderr) + + if (error !== null) { + console.log('exec error: ' + error) + } + + let responseObj; + + if (stderr) { + responseObj = { + 'msg': 'error', + 'result': stderr + }; + } else { + responseObj = { + 'msg': 'success', + 'result': stdout + }; + } + + res.end(JSON.stringify(responseObj)); + }); + } +}); + /* * type: POST * params: payload