diff --git a/remix-simulator/bin/ethsim b/remix-simulator/bin/ethsim index 2d583af564..a1257b98d6 100755 --- a/remix-simulator/bin/ethsim +++ b/remix-simulator/bin/ethsim @@ -23,11 +23,13 @@ program .option('-p, --port [port]', 'specify port') .option('-b, --ip [host]', 'specify host') .option('-c, --coinbase [coinbase]', 'specify host') + .option('--rpc', 'run rpc server only') .parse(process.argv) const Server = require('../src/server') const server = new Server({ - coinbase: program.coinbase || "0x0000000000000000000000000000000000000000" + coinbase: program.coinbase || "0x0000000000000000000000000000000000000000", + rpc: program.rpc }) server.start(program.host || '127.0.0.1', program.port || 8545) diff --git a/remix-simulator/src/server.js b/remix-simulator/src/server.js index 92bb43aad9..7059562afd 100644 --- a/remix-simulator/src/server.js +++ b/remix-simulator/src/server.js @@ -14,6 +14,7 @@ class Server { }).catch((error) => { log(error) }) + this.rpcOnly = options.rpc; } start (host, port) { @@ -24,28 +25,31 @@ class Server { app.use(bodyParser.json()) app.get('/', (req, res) => { + console.dir("/ request") res.send('Welcome to remix-simulator') }) - app.use((req, res) => { - this.provider.sendAsync(req.body, (err, jsonResponse) => { - if (err) { - return res.send(JSON.stringify({error: err})) - } - res.send(jsonResponse) - }) - }) - - app.ws('/', (ws, req) => { - ws.on('message', function (msg) { - this.provider.sendAsync(JSON.parse(msg), (err, jsonResponse) => { + if (this.rpcOnly) { + app.use((req, res) => { + this.provider.sendAsync(req.body, (err, jsonResponse) => { if (err) { - return ws.send(JSON.stringify({error: err})) + return res.send(JSON.stringify({ error: err })) } - ws.send(JSON.stringify(jsonResponse)) + res.send(jsonResponse) }) }) - }) + } else { + app.ws('/', (ws, req) => { + ws.on('message', (msg) => { + this.provider.sendAsync(JSON.parse(msg), (err, jsonResponse) => { + if (err) { + return ws.send(JSON.stringify({ error: err })) + } + ws.send(JSON.stringify(jsonResponse)) + }) + }) + }) + } app.listen(port, host, () => log('Remix Simulator listening on port ' + host + ':' + port)) }