diff --git a/config/nginx/default.conf b/config/nginx/default.conf index 74e3212754cdecdf9a41d7c02d263787ec0599a9..5b1c74c65d64cf578fc16e13a6b4a7a1a6b60f84 100644 --- a/config/nginx/default.conf +++ b/config/nginx/default.conf @@ -92,8 +92,4 @@ server { # deny access to .htaccess files, if Apache's document root # concurs with nginx's one - # - #location ~ /\.ht { - # deny all; - #} } \ No newline at end of file diff --git a/js/src/collaborations/eclipsefdn.weighted-working-groups.js b/js/src/collaborations/eclipsefdn.weighted-working-groups.js index e1232e6037d0afdbd91d85b089d6b01414ac0aff..9ed652a9c3d41b0daae124ea16efcd1cfd29813e 100644 --- a/js/src/collaborations/eclipsefdn.weighted-working-groups.js +++ b/js/src/collaborations/eclipsefdn.weighted-working-groups.js @@ -73,34 +73,40 @@ function getUniqueRandomWorkingGroups(workingGroupsCategorizedByWeight, weightBu } async function getWeightedRandomWorkingGroups(count) { - const cachedWorkingGroups = JSON.parse(sessionStorage.getItem('weighted-working-groups')); - const isCached = cachedWorkingGroups != null; + try { + const cachedWorkingGroups = JSON.parse(sessionStorage.getItem('weighted-working-groups')); + const isCached = cachedWorkingGroups != null; - // Only return the cached working groups if the count hasn't changed since last time run - if (isCached && cachedWorkingGroups.length === count) return cachedWorkingGroups; + // Only return the cached working groups if the count hasn't changed since last time run + if (isCached && cachedWorkingGroups.length === count) return [cachedWorkingGroups, null]; - const response = await fetch('https://membership.eclipse.org/api/working_groups'); - const workingGroups = await response.json(); + const response = await fetch('https://api.eclipse.org/working-groups/'); + if (!response.ok) throw new Error('Could not fetch from the Working Group API'); - const weightBuckets = Object - .values(weights) - .filter(removeDuplicates); + const workingGroups = await response.json(); - // Create an object where the key is a bucket (or weight), and the value an array of working groups tied to that bucket - const weightBucketObject = weightBuckets.reduce((acc, bucket) => ({...acc, [bucket]: [] }), {}) + const weightBuckets = Object + .values(weights) + .filter(removeDuplicates); - const workingGroupsCategorizedByWeight = workingGroups.reduce((acc, wg) => { - const weight = weights[wg.alias] || weights.default; - acc[weight].push(wg); + // Create an object where the key is a bucket (or weight), and the value an array of working groups tied to that bucket + const weightBucketObject = weightBuckets.reduce((acc, bucket) => ({...acc, [bucket]: [] }), {}) - return acc; - }, { ...weightBucketObject }); + const workingGroupsCategorizedByWeight = workingGroups.reduce((acc, wg) => { + const weight = weights[wg.alias] || weights.default; + acc[weight].push(wg); - // Retrieves weighted random working groups and stores it in session storage cache - const randomWorkingGroups = getUniqueRandomWorkingGroups(workingGroupsCategorizedByWeight, weightBuckets, count); - sessionStorage.setItem('weighted-working-groups', JSON.stringify(randomWorkingGroups)); + return acc; + }, { ...weightBucketObject }); - return randomWorkingGroups; + // Retrieves weighted random working groups and stores it in session storage cache + const randomWorkingGroups = getUniqueRandomWorkingGroups(workingGroupsCategorizedByWeight, weightBuckets, count); + sessionStorage.setItem('weighted-working-groups', JSON.stringify(randomWorkingGroups)); + + return [randomWorkingGroups, null]; + } catch (error) { + return [null, error]; + } }; const matchHeightForLogos = (baseElement) => { @@ -132,8 +138,14 @@ const getWorkingGroupLogo = ({ alias, logo } = workingGroup) => { element.innerHTML = template({ isFetching: true, items: new Array(options.count) , wrapperClass: options.wrapperClass }) - const workingGroups = await getWeightedRandomWorkingGroups(options.count); + const [workingGroups, error] = await getWeightedRandomWorkingGroups(options.count); + if (error) { + element.innerHTML = `<p class="alert alert-danger">Error when attempting to load working groups.</p>`; + console.error(error); + return; + } + const data = { isFetching: false, wrapperClass: options.wrapperClass,