mirror of
https://github.com/ryan-haskell/elm-spa.git
synced 2024-08-17 00:10:27 +03:00
dont crash when unknown websocket requests come in
This commit is contained in:
parent
f97dc4ebd6
commit
2dad9f9662
@ -52,9 +52,11 @@ const start = async () => new Promise((resolve, reject) => {
|
||||
const ws = new websocket.server({ httpServer: server })
|
||||
const script = ` new WebSocket('ws://' + window.location.host, 'elm-spa').onmessage = function () { window.location.reload() } `
|
||||
ws.on('request', (req) => {
|
||||
const conn = req.accept('elm-spa', req.origin)
|
||||
connections[req.remoteAddress] = conn
|
||||
conn.on('close', () => delete connections[conn.remoteAddress])
|
||||
try {
|
||||
const conn = req.accept('elm-spa', req.origin)
|
||||
connections[req.remoteAddress] = conn
|
||||
conn.on('close', () => delete connections[conn.remoteAddress])
|
||||
} catch (_) { /* Safely ignores unknown requests */ }
|
||||
})
|
||||
|
||||
// Send reload if any files change
|
||||
|
Loading…
Reference in New Issue
Block a user