Skip to content

Commit

Permalink
Support assetPrefix specific protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
genetschneider committed Nov 9, 2021
1 parent bcf2528 commit 9591abf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/next/client/dev/error-overlay/websocket.ts
Expand Up @@ -2,6 +2,17 @@ let source: WebSocket
const eventCallbacks: ((event: any) => void)[] = []
let lastActivity = Date.now()

function getSocketProtocol(assetPrefix: string): string {
let protocol = location.protocol

try {
// assetPrefix is a url
protocol = new URL(assetPrefix).protocol
} catch (_) {}

return protocol === 'http:' ? 'ws' : 'wss'
}

export function addMessageListener(cb: (event: any) => void) {
eventCallbacks.push(cb)
}
Expand Down Expand Up @@ -32,7 +43,7 @@ export function connectHMR(options: {
function init() {
if (source) source.close()
const { hostname, port } = location
const protocol = location.protocol === 'http:' ? 'ws' : 'wss'
const protocol = getSocketProtocol(options.assetPrefix || '')
const assetPrefix = options.assetPrefix.replace(/^\/+/, '')

let url = `${protocol}://${hostname}:${port}${
Expand Down

0 comments on commit 9591abf

Please sign in to comment.