UNPKG

terriajs

Version:

Geospatial data visualization platform.

40 lines 1.74 kB
import isDefined from "../../Core/isDefined"; import UrlMixin from "../../ModelMixins/UrlMixin"; /** * The terriajs-server is the default server that proxies a URL associated with a catalog item, if necessary. * @param {CatalogItem} [catalogItem] The catalog item. * @param {string} url The URL to be proxied. * @param {string} [cacheDuration] The cache duration to use if catalogItem.cacheDuration is undefined. * @returns {string} The URL, now cached if necessary. */ export default function proxyCatalogItemUrl(catalogItem, url, cacheDuration) { const corsProxy = catalogItem?.terria?.corsProxy; if (isDefined(corsProxy) && (corsProxy.shouldUseProxy(url) || (UrlMixin.isMixedInto(catalogItem) && catalogItem.forceProxy))) { cacheDuration = (UrlMixin.isMixedInto(catalogItem) ? catalogItem.cacheDuration : undefined) ?? cacheDuration; return corsProxy.getURL(url, cacheDuration); } else { return url; } } /** * Similar to {@link proxyCatalogItemUrl}, but only returns proxy base url, not full URL (for example `proxy/`, instead of `proxy/some/other/resource`) */ export function proxyCatalogItemBaseUrl(catalogItem, url, cacheDuration) { const corsProxy = catalogItem?.terria?.corsProxy; if (isDefined(corsProxy) && (corsProxy.shouldUseProxy(url) || (UrlMixin.isMixedInto(catalogItem) && catalogItem.forceProxy))) { cacheDuration = (UrlMixin.isMixedInto(catalogItem) ? catalogItem.cacheDuration : undefined) ?? cacheDuration; return corsProxy.getProxyBaseURL(cacheDuration); } } //# sourceMappingURL=proxyCatalogItemUrl.js.map