Download next.js/packages/next/src/client/dev/hot-reloader/get-socket-url.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 815 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/client/dev/hot-reloader/get-socket-url.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/client/dev/hot-reloader/get-socket-url.ts
-
curl -L -o get-socket-url.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/client/dev/hot-reloader/get-socket-url.ts
815 Bytes
| import { normalizedAssetPrefix } from '../../../shared/lib/normalized-asset-prefix' | |
| function getSocketProtocol(assetPrefix: string): string { | |
| let protocol = window.location.protocol | |
| try { | |
| // assetPrefix is a url | |
| protocol = new URL(assetPrefix).protocol | |
| } catch {} | |
| return protocol === 'http:' ? 'ws:' : 'wss:' | |
| } | |
| export function getSocketUrl(assetPrefix: string | undefined): string { | |
| const prefix = normalizedAssetPrefix(assetPrefix) | |
| const protocol = getSocketProtocol(assetPrefix || '') | |
| if (URL.canParse(prefix)) { | |
| // since normalized asset prefix is ensured to be a URL format, | |
| // we can safely replace the protocol | |
| return prefix.replace(/^http/, 'ws') | |
| } | |
| const { hostname, port } = window.location | |
| return `${protocol}//${hostname}${port ? `:${port}` : ''}${prefix}` | |
| } | |