react-cosmos
Version:
Sandbox for developing and testing UI components in isolation
22 lines (21 loc) • 844 B
JavaScript
import { createRendererUrl, pickRendererUrl } from 'react-cosmos-core';
import { getServerAddress, getServerHost } from './serverAddress.js';
export function getRemoteRendererUrl(config) {
const rendererUrl = pickRendererUrl(config.rendererUrl, 'dev');
return rendererUrl
? fullServerUrl(config, createRendererUrl(rendererUrl)).toString()
: null;
}
function fullServerUrl(config, rendererUrl) {
// Renderer URL can be absolute or relative, depending on whether the renderer
// is running on the same host/port as the Cosmos UI.
try {
const url = new URL(rendererUrl);
url.hostname = getServerHost(config);
return url;
}
catch {
const protocol = config.https ? 'https' : 'http';
return new URL(rendererUrl, `${protocol}://${getServerAddress(config)}`);
}
}