Commit af5b772a authored by Iuri Matias's avatar Iuri Matias

add websocket support for remix-sim

parent 8846f8d4
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
"body-parser": "^1.18.2", "body-parser": "^1.18.2",
"color-support": "^1.1.3", "color-support": "^1.1.3",
"express": "^4.16.3", "express": "^4.16.3",
"express-ws": "^4.0.0",
"fast-async": "^6.3.7", "fast-async": "^6.3.7",
"merge": "^1.2.0", "merge": "^1.2.0",
"remix-lib": "0.3.13", "remix-lib": "0.3.13",
......
const express = require('express') const express = require('express')
const bodyParser = require('body-parser') const bodyParser = require('body-parser')
const app = express() const app = express()
const expressWs = require('express-ws')(app)
const Provider = require('./provider') const Provider = require('./provider')
const log = require('./utils/logs.js') const log = require('./utils/logs.js')
...@@ -22,4 +23,15 @@ app.use(function (req, res) { ...@@ -22,4 +23,15 @@ app.use(function (req, res) {
}) })
}) })
app.ws('/', function(ws, req) {
ws.on('message', function(msg) {
provider.sendAsync(JSON.parse(msg), (err, jsonResponse) => {
if (err) {
ws.send({error: err});
}
ws.send(JSON.stringify(jsonResponse));
})
});
});
app.listen(8545, () => log('Remix Simulator listening on port 8545!')) app.listen(8545, () => log('Remix Simulator listening on port 8545!'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment