* @param {{ * manifest_path: string; * env: Record * }} opts
({ manifest_path, env })
| 14 | * }} opts |
| 15 | */ |
| 16 | async function generate_fallback({ manifest_path, env }) { |
| 17 | /** @type {import('types').ValidatedKitConfig} */ |
| 18 | const config = (await load_config()).kit; |
| 19 | |
| 20 | installPolyfills(); |
| 21 | |
| 22 | const server_root = join(config.outDir, 'output'); |
| 23 | |
| 24 | /** @type {import('types').ServerInternalModule} */ |
| 25 | const { set_building } = await import(pathToFileURL(`${server_root}/server/internal.js`).href); |
| 26 | |
| 27 | /** @type {import('types').ServerModule} */ |
| 28 | const { Server } = await import(pathToFileURL(`${server_root}/server/index.js`).href); |
| 29 | |
| 30 | /** @type {import('@sveltejs/kit').SSRManifest} */ |
| 31 | const manifest = (await import(pathToFileURL(manifest_path).href)).manifest; |
| 32 | |
| 33 | set_building(); |
| 34 | |
| 35 | const server = new Server(manifest); |
| 36 | await server.init({ env }); |
| 37 | |
| 38 | const response = await server.respond(new Request(config.prerender.origin + '/[fallback]'), { |
| 39 | getClientAddress: () => { |
| 40 | throw new Error('Cannot read clientAddress during prerendering'); |
| 41 | }, |
| 42 | prerendering: { |
| 43 | fallback: true, |
| 44 | dependencies: new Map(), |
| 45 | remote_responses: new Map() |
| 46 | }, |
| 47 | read: (file) => readFileSync(join(config.files.assets, file)) |
| 48 | }); |
| 49 | |
| 50 | if (response.ok) { |
| 51 | return await response.text(); |
| 52 | } |
| 53 | |
| 54 | throw new Error(`Could not create a fallback page — failed with status ${response.status}`); |
| 55 | } |
no test coverage detected