chore: harden docs demo config fetch

This commit is contained in:
3252a8
2026-05-28 08:21:54 +03:00
parent d46324cb6a
commit 93c9dde572
+26 -9
View File
@@ -13,6 +13,7 @@ const localesDir = path.join(repoRoot, 'locales');
const runtimeBase = '/demo/runtime'; const runtimeBase = '/demo/runtime';
const installGuidesConfigUrl = const installGuidesConfigUrl =
'https://raw.githubusercontent.com/legiz-ru/my-remnawave/main/sub-page/subpage-config/multiapp.json'; 'https://raw.githubusercontent.com/legiz-ru/my-remnawave/main/sub-page/subpage-config/multiapp.json';
const installGuidesConfigRetries = 3;
const isWindows = process.platform === 'win32'; const isWindows = process.platform === 'win32';
const npmExecPath = process.env.npm_execpath || ''; const npmExecPath = process.env.npm_execpath || '';
@@ -92,6 +93,10 @@ async function copyRuntimeAsset(name) {
await copyFile(path.join(templatesDir, name), path.join(runtimeDir, name)); await copyFile(path.join(templatesDir, name), path.join(runtimeDir, name));
} }
function wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function jsonScriptPayload(value) { function jsonScriptPayload(value) {
return JSON.stringify(value).replace(/</g, '\\u003c'); return JSON.stringify(value).replace(/</g, '\\u003c');
} }
@@ -105,16 +110,28 @@ async function demoI18nPayload() {
} }
async function installGuidesConfigPayload() { async function installGuidesConfigPayload() {
const response = await fetch(installGuidesConfigUrl, { let lastError;
headers: { accept: 'application/json' },
}); for (let attempt = 1; attempt <= installGuidesConfigRetries; attempt += 1) {
if (!response.ok) { try {
throw new Error( const response = await fetch(installGuidesConfigUrl, {
`Unable to download demo install guides config (${response.status} ${response.statusText})`, headers: { accept: 'application/json' },
); });
if (!response.ok) {
throw new Error(
`Unable to download demo install guides config (${response.status} ${response.statusText})`,
);
}
const config = await response.json();
return `${JSON.stringify(config, null, 2)}\n`;
} catch (error) {
lastError = error;
if (attempt === installGuidesConfigRetries) break;
await wait(500 * attempt);
}
} }
const config = await response.json();
return `${JSON.stringify(config, null, 2)}\n`; throw lastError;
} }
async function appHtml() { async function appHtml() {