File tree Expand file tree Collapse file tree
client/components/react-dev-overlay/internal/helpers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,16 +11,15 @@ function getSocketProtocol(assetPrefix: string): string {
1111 return protocol === 'http:' ? 'ws' : 'wss'
1212}
1313
14- export function getSocketUrl ( assetPrefix : string ) : string {
14+ export function getSocketUrl ( assetPrefix : string | undefined ) : string {
1515 const { hostname, port } = window . location
16- const protocol = getSocketProtocol ( assetPrefix )
16+ const protocol = getSocketProtocol ( assetPrefix || '' )
1717 const prefix = normalizedAssetPrefix ( assetPrefix )
1818
19- let url = `${ protocol } ://${ hostname } :${ port } ${ prefix && prefix !== '' ? `/${ prefix } ` : '' } `
20-
21- if ( prefix . startsWith ( 'http' ) ) {
22- url = `${ protocol } ://${ prefix . split ( '://' , 2 ) [ 1 ] } `
19+ // same check but on original assetPrefix value
20+ if ( assetPrefix ?. replace ( / ^ \/ + / , '' ) . startsWith ( 'http' ) ) {
21+ return `${ protocol } ://${ prefix } `
2322 }
2423
25- return url
24+ return ` ${ protocol } :// ${ hostname } : ${ port } ${ prefix } `
2625}
Original file line number Diff line number Diff line change 1- export function normalizedAssetPrefix ( assetPrefix : string ) : string {
2- const escapedAssetPrefix = assetPrefix . replace ( / ^ \/ + / , '' )
1+ export function normalizedAssetPrefix ( assetPrefix : string | undefined ) : string {
2+ const escapedAssetPrefix = assetPrefix ? .replace ( / ^ \/ + / , '' ) || false
33
4- if ( escapedAssetPrefix . startsWith ( 'http' ) ) {
4+ // assetPrefix as a url
5+ if ( escapedAssetPrefix && escapedAssetPrefix . startsWith ( 'http' ) ) {
56 return escapedAssetPrefix . split ( '://' , 2 ) [ 1 ]
67 }
78
8- return `${ escapedAssetPrefix ? `/${ escapedAssetPrefix } ` : '' } `
9+ // assetPrefix is set to `undefined` or '/'
10+ if ( ! escapedAssetPrefix || escapedAssetPrefix === '' ) {
11+ return ''
12+ }
13+
14+ // assetPrefix is a common path but escaped so let's add one leading slash
15+ return `/${ escapedAssetPrefix } `
916}
You can’t perform that action at this time.
0 commit comments