Skip to content

Commit

Permalink
Attempt fetching an index.yaml using cors anywhere if it fails. (#582)
Browse files Browse the repository at this point in the history
* Remove preview limitation notice.

* Attempt fetching with cors anywhere if the fetch fails.

* Run prettier.
  • Loading branch information
Oliver Ponder committed May 14, 2019
1 parent c380455 commit 82da81d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
25 changes: 23 additions & 2 deletions src/actions/catalogActions.js
Expand Up @@ -5,16 +5,37 @@ import yaml from 'js-yaml';
// loadCatalog takes a catalog object and tries to load further data.
function loadCatalogIndex(catalog) {
return fetch(catalog.spec.storage.URL + 'index.yaml', { mode: 'cors' })
.catch(() => {
console.log(
`Fetch error for ${
catalog.spec.storage.URL
}, attempting with cors anywhere.`
);
return fetch(
'https://cors-anywhere.herokuapp.com/' +
catalog.spec.storage.URL +
'index.yaml',
{ mode: 'cors' }
);
})
.catch(error => {
console.error('Fetch error: ', error);
throw error;
})
.then(response => {
return response.text();
if (response.status === 200) {
return response.text();
} else {
throw `Could not fetch index.yaml at ${catalog.spec.storage.URL}`;
}
})
.then(body => {
let rawCatalog = yaml.safeLoad(body);
catalog.apps = rawCatalog.entries;
return catalog;
})
.catch(error => {
console.error(error);
console.error('YAML error: ', error);
throw error;
});
}
Expand Down
6 changes: 0 additions & 6 deletions src/components/app_catalog/catalogs/index.js
Expand Up @@ -54,12 +54,6 @@ class Catalogs extends React.Component {
</div>
</React.Fragment>
)}
<p className='well'>
<b>Preview Limitations:</b>
<br />
During the preview you&apos;ll only be able to browse apps.
Installing apps is coming soon!
</p>
</React.Fragment>
</DocumentTitle>
);
Expand Down

0 comments on commit 82da81d

Please sign in to comment.