mirror of
https://github.com/ryan-haskell/elm-spa.git
synced 2024-11-22 03:12:01 +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 ws = new websocket.server({ httpServer: server })
|
||||||
const script = ` new WebSocket('ws://' + window.location.host, 'elm-spa').onmessage = function () { window.location.reload() } `
|
const script = ` new WebSocket('ws://' + window.location.host, 'elm-spa').onmessage = function () { window.location.reload() } `
|
||||||
ws.on('request', (req) => {
|
ws.on('request', (req) => {
|
||||||
const conn = req.accept('elm-spa', req.origin)
|
try {
|
||||||
connections[req.remoteAddress] = conn
|
const conn = req.accept('elm-spa', req.origin)
|
||||||
conn.on('close', () => delete connections[conn.remoteAddress])
|
connections[req.remoteAddress] = conn
|
||||||
|
conn.on('close', () => delete connections[conn.remoteAddress])
|
||||||
|
} catch (_) { /* Safely ignores unknown requests */ }
|
||||||
})
|
})
|
||||||
|
|
||||||
// Send reload if any files change
|
// Send reload if any files change
|
||||||
|
Loading…
Reference in New Issue
Block a user