.map(function (asset) { const next = urlm.getHostname(asset); if (hostname !== next) { hostname = next; // New hostname, so install GET handler for that host toolbox.router.get('*', toolbox.networkFirst, { origin: hostname, // any/all CDNs get 3 seconds max networkTimeoutSeconds: 3 }); } // Precache the asset in 'install' return asset; })
/** * Cache background images for the app * * @param {Object} payload - The stores payload object. * @param {Object} payload.BackgroundStore - The dehydrated BackgroundStore. * @param {Object} payload.BackgroundStore.backgroundUrls - The background urls * object, containing name-values for backgrounds at imageServiceUrl. * @param {String} payload.BackgroundStore.imageServiceUrl - The url to the * image service. */ export default function backgroundHandler (payload) { const backgroundStore = payload.BackgroundStore; debug('install background image handler', backgroundStore); // Install a precaching, read-thru cache on all requests to the background // image service toolbox.router.get('*', precacheBackgrounds.bind(null, backgroundStore.backgroundUrls), { debug: toolbox.options.debug, origin: urlm.getHostname(backgroundStore.imageServiceUrl) } ); // Nothing deferred (yet), so return a resolved Promise return Promise.resolve(); }
var hostnames = _.uniq(data.assets.map(function (asset) { return urlm.getHostname(asset); }));
testUrls.forEach((url, index) => { expect(urlm.getHostname(url)).to.eql(hosts[index].replace(/:.+$/, '')); });