Skip to content

Commit 8802c07

Browse files
committed
provide plaintext/spa option
1 parent 064d41d commit 8802c07

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/adapter-cloudflare/index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ import './ambient.js';
44
export default function plugin(options?: AdapterOptions): Adapter;
55

66
export interface AdapterOptions {
7+
/**
8+
* Whether to render a plaintext 404.html page, or a rendered SPA fallback page. This page will
9+
* only be served when a request that matches an entry in `routes.exclude` fails to match an asset.
10+
*
11+
* Most of the time `plaintext` is sufficient, but if you are using `routes.exclude` to manually
12+
* exclude a set of prerendered pages without exceeding the 100 route limit, you may wish to
13+
* use `spa` instead.
14+
*
15+
* @default 'plaintext'
16+
*/
17+
fallback?: 'plaintext' | 'spa';
18+
719
/**
820
* Customize the automatically-generated `_routes.json` file
921
* https://developers.cloudflare.com/pages/platform/functions/routing/#create-a-_routesjson-file

packages/adapter-cloudflare/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ export default function (options = {}) {
1919
builder.mkdirp(tmp);
2020

2121
// generate plaintext 404.html first which can then be overridden by prerendering, if the user defined such a page
22-
writeFileSync(`${dest}/404.html`, 'Not Found');
22+
const fallback = path.join(dest, '404.html');
23+
if (options.fallback === 'spa') {
24+
await builder.generateFallback(fallback);
25+
} else {
26+
writeFileSync(fallback, 'Not Found');
27+
}
2328

2429
const dest_dir = `${dest}${builder.config.kit.paths.base}`;
2530
const written_files = builder.writeClient(dest_dir);

0 commit comments

Comments
 (0)