import { getConf } from '../configuration';

/**
 * Resolves a resource URL: absolute URLs (starting with "http") are returned as-is,
 * otherwise the host is prepended.
 * @param {string} url - Resource path or absolute URL
 * @param {string} [host=getConf('network.host')] - Host to prepend for relative URLs (uses default if falsy)
 * @returns {string} Resolved URL
 */
export function getUrl(url, host) {
    if (url == null || url === '') {
        return url;
    }
    const resolvedHost = host || getConf('network.host');
    return url.startsWith('http') ? url : `${resolvedHost}${url}`;
}
