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 651b632
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/next/client/dev/error-overlay/websocket.ts
Expand Up @@ -2,6 +2,19 @@ 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

console.log('is a url!', protocol, new URL(assetPrefix))
} catch (_) {}

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

export function addMessageListener(cb: (event: any) => void) {
eventCallbacks.push(cb)
}
Expand Down Expand Up @@ -32,7 +45,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 651b632

Please sign in to comment.