I have a Koa server using webpack-dev-middleware and webpack-hot-middleware doing hot module replacement (HMR), so the middleware uses a websocket to push changes to the client.
But my application code also needs its own websocket connection between the client and the Koa server. I have no idea how to achieve that? Seems like the two are conflicting. Can I have them side by side?
My server code looks something like this
const compiler = webpack(webpackConfig)
const app = new Koa()
app.use(webpackDevMiddleware(compiler, {
quiet: true,
noInfo: true
stats: {
colors: true,
reasons: true
}
})))
app.use(webpackHotMiddleware(compiler))
const server = require('http').createServer(app.callback())
const io = require('socket.io')(server)
io.on('connection', function() { console.log('socket connection!!') })
And my client something like
import Client from 'socket.io-client'
const io = Client()
io.on('connection', (socket) => {
console.log('+++ io connected! ++++')
io.on('disconnect', () => { console.log('disconnected', socket) })
})
The HMR socket is working correctly, but the other one is trying to talk to
GET /socket.io/?EIO=3&transport=polling&t=1446911862461-0
and those requests are failing.
How do I create a websocket that doesn't clash with the HMR socket?