Merge pull request #1083 from ethereum/sim_ws

add websocket support for remix-sim
pull/5370/head
yann300 6 years ago committed by GitHub
commit 18ed8594d5
  1. 1
      remix-simulator/package.json
  2. 18
      remix-simulator/src/server.js

@ -22,6 +22,7 @@
"body-parser": "^1.18.2",
"color-support": "^1.1.3",
"express": "^4.16.3",
"express-ws": "^4.0.0",
"fast-async": "^6.3.7",
"merge": "^1.2.0",
"remix-lib": "0.3.13",

@ -1,9 +1,12 @@
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const expressWs = require('express-ws')
const Provider = require('./provider')
const log = require('./utils/logs.js')
expressWs(app)
var provider = new Provider()
app.use(bodyParser.urlencoded({extended: true}))
@ -13,13 +16,24 @@ app.get('/', (req, res) => {
res.send('Welcome to remix-simulator')
})
app.use(function (req, res) {
app.use((req, res) => {
provider.sendAsync(req.body, (err, jsonResponse) => {
if (err) {
res.send({error: err})
return res.send(JSON.stringify({error: err}))
}
res.send(jsonResponse)
})
})
app.ws('/', (ws, req) => {
ws.on('message', function (msg) {
provider.sendAsync(JSON.parse(msg), (err, jsonResponse) => {
if (err) {
return ws.send(JSON.stringify({error: err}))
}
ws.send(JSON.stringify(jsonResponse))
})
})
})
app.listen(8545, () => log('Remix Simulator listening on port 8545!'))

Loading…
Cancel
Save