diff --git a/docs/content/3.config.md b/docs/content/3.config.md index c69c4d49ed..58ef1dc708 100644 --- a/docs/content/3.config.md +++ b/docs/content/3.config.md @@ -347,7 +347,9 @@ Default: failOnError: false, crawlLinks: false, ignore: [], - routes: [] + routes: [], + retries: 3, + retryDelay: 500 } ``` @@ -372,6 +374,8 @@ Set `autoSubfolderIndex` lets you control how to generate the files in the `.out This option is useful when your hosting provider does not give you an option regarding the trailing slash. +The prerenderer will attempt to render pages 3 times with a delay of 500ms. Use `retry` and `retryDelay` to change this behavior. + ## Directories ### `rootDir` diff --git a/src/options.ts b/src/options.ts index 58ba2043f0..cb8572281f 100644 --- a/src/options.ts +++ b/src/options.ts @@ -79,6 +79,8 @@ const NitroDefaults: NitroConfig = { autoSubfolderIndex: true, concurrency: 1, interval: 0, + retry: 3, + retryDelay: 500, failOnError: false, crawlLinks: false, ignore: [], diff --git a/src/prerender.ts b/src/prerender.ts index 9bb7ca293d..acc384950f 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -5,6 +5,7 @@ import chalk from "chalk"; import { createRouter as createRadixRouter, toRouteMatcher } from "radix3"; import { defu } from "defu"; import mime from "mime"; +import type { $Fetch } from "ofetch"; import { createNitro } from "./nitro"; import { build } from "./build"; import type { Nitro, NitroRouteRules, PrerenderRoute } from "./types"; @@ -77,7 +78,9 @@ export async function prerender(nitro: Nitro) { nitroRenderer.options.output.serverDir, "index.mjs" ); - const { localFetch } = await import(pathToFileURL(serverEntrypoint).href); + const { localFetch } = (await import( + pathToFileURL(serverEntrypoint).href + )) as { localFetch: $Fetch }; // Create route rule matcher const _routeRulesMatcher = toRouteMatcher( @@ -164,13 +167,15 @@ export async function prerender(nitro: Nitro) { // Fetch the route const encodedRoute = encodeURI(route); - const res = await (localFetch( + + const res = await localFetch( withBase(encodedRoute, nitro.options.baseURL), { headers: { "x-nitro-prerender": encodedRoute }, + retry: nitro.options.prerender.retry, + retryDelay: nitro.options.prerender.retryDelay, } - ) as ReturnType); - + ); // Data will be removed as soon as written to the disk let dataBuff: Buffer | undefined = Buffer.from(await res.arrayBuffer()); diff --git a/src/types/nitro.ts b/src/types/nitro.ts index d0344ac926..24ff0d60cf 100644 --- a/src/types/nitro.ts +++ b/src/types/nitro.ts @@ -297,6 +297,16 @@ export interface NitroOptions extends PresetOptions { failOnError: boolean; ignore: string[]; routes: string[]; + /** + * Amount of retries. Pass Infinity to retry indefinitely. + * @default 3 + */ + retry: number; + /** + * Delay between each retry in ms. + * @default 500 + */ + retryDelay: number; }; // Rollup