UNPKG

@redocly/cli

Version:

[@Redocly](https://redocly.com) CLI is your all-in-one OpenAPI utility. It builds, manages, improves, and quality-checks your OpenAPI descriptions, all of which comes in handy for various phases of the API Lifecycle. Create your own rulesets to make API g

60 lines (50 loc) 1.44 kB
(function run() { const Socket = window.SimpleWebsocket; const port = window.__OPENAPI_CLI_WS_PORT; const host = window.__OPENAPI_CLI_WS_HOST; let socket; reconnect(); function getFormattedHost() { // Use localhost when bound to all interfaces if (host === '::' || host === '0.0.0.0') { return 'localhost'; } // Other IPv6 addresses must be wrapped in brackets if (host.includes('::')) { return `[${host}]`; } // Otherwise return as-is return host; } function reconnect() { socket = new Socket(`ws://${getFormattedHost()}:${port}`); socket.on('connect', () => { socket.send('{"type": "ping"}'); }); socket.on('data', (data) => { const message = JSON.parse(data); switch (message.type) { case 'pong': console.log('[hot] hot reloading connected'); break; case 'reload': console.log('[hot] full page reload'); window.location.reload(); break; default: console.log(`[hot] ${message.type} received`); } }); socket.on('close', () => { socket.destroy(); console.log('[hot] Connection lost, trying to reconnect in 4s'); setTimeout(() => { reconnect(); }, 4000); }); socket.on('error', () => { console.log('[hot] Error connecting to hot reloading server'); socket.destroy(); }); } })();