Skip to content

Commit

Permalink
Fix an error that being logged in the console when Webpack is using W…
Browse files Browse the repository at this point in the history
…ebSocket and not SockJS
  • Loading branch information
giladgd authored and gregberge committed Nov 14, 2022
1 parent 8aa4edf commit eee7dfd
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/entries/devserver.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ if (typeof __resourceQuery === 'string' && __resourceQuery) {
sockOptions = querystring.parse(__resourceQuery.substr(1))
}

const connection = new SockJS(
`${window.location.protocol}//${
sockOptions.sockHost || window.location.hostname
}:${sockOptions.sockPort || window.location.port}${
sockOptions.sockPath || '/sockjs-node'
}`,
)
const connection =
sockOptions.sockPath === '/ws' && typeof WebSocket !== 'undefined'
? new WebSocket(
`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${
sockOptions.sockHost || window.location.hostname
}:${sockOptions.sockPort || window.location.port}${
sockOptions.sockPath || '/ws'
}`,
)
: new SockJS(
`${window.location.protocol}//${
sockOptions.sockHost || window.location.hostname
}:${sockOptions.sockPort || window.location.port}${
sockOptions.sockPath || '/sockjs-node'
}`,
)

connection.onmessage = function onmessage(e) {
const { type, data } = JSON.parse(e.data)
Expand Down

0 comments on commit eee7dfd

Please sign in to comment.