Make the code cleaner by extracting the checkRef into it's own function

This commit is contained in:
Norbert de Langen 2020-08-18 13:50:57 +02:00
parent 26f11fe6c7
commit 627cee152e
No known key found for this signature in database
GPG Key ID: 976651DA156C2825

View File

@ -37,6 +37,12 @@ const getAutoRefs = async (options) => {
return list.filter(Boolean);
};
const checkRef = (url) =>
fetch(`${url}/iframe.html`).then(
({ ok }) => ok,
() => false
);
const stripTrailingSlash = (url) => url.replace(/\/$/, '');
const toTitle = (input) => {
@ -96,9 +102,7 @@ async function getManagerWebpackConfig(options, presets) {
// verify the refs are publicly reachable, if they are not we'll require stories.json at runtime, otherwise the ref won't work
await Promise.all(
Object.entries(refs).map(async ([k, value]) => {
const { ok } = await fetch(`${value.url}/iframe.html`).catch((e) => ({
ok: false,
}));
const ok = checkRef(value.url);
refs[k] = { ...value, type: ok ? 'server-checked' : 'unknown' };
})