fix: prerender bailout

This commit is contained in:
iCrawl
2024-05-24 02:10:07 +02:00
parent 7f467ed2d1
commit a35d760421
4 changed files with 38 additions and 49 deletions

View File

@@ -1,6 +1,5 @@
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { notFound } from 'next/navigation';
import { ENV } from './env';
export async function fetchNode({
@@ -15,32 +14,22 @@ export async function fetchNode({
const normalizeItem = item.split(encodeURIComponent(':')).join('.').toLowerCase();
if (ENV.IS_LOCAL_DEV) {
try {
const fileContent = await readFile(
join(
process.cwd(),
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizeItem}.api.json`,
),
'utf8',
);
return JSON.parse(fileContent);
} catch (error_) {
console.error(error_);
notFound();
}
}
try {
const isMainVersion = version === 'main';
const fileContent = await fetch(
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizeItem}.api.json`,
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
const fileContent = await readFile(
join(
process.cwd(),
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizeItem}.api.json`,
),
'utf8',
);
return await fileContent.json();
} catch (error_) {
console.error(error_);
notFound();
return JSON.parse(fileContent);
}
const isMainVersion = version === 'main';
const fileContent = await fetch(
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizeItem}.api.json`,
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
);
return fileContent.json();
}