add optioan to specify rpc server option

pull/7/head
Iuri Matias 6 years ago
parent dc0865fc8c
commit 45e865d542
  1. 4
      remix-simulator/bin/ethsim
  2. 34
      remix-simulator/src/server.js

@ -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)

@ -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))
}

Loading…
Cancel
Save