From 3908cb397e55121fe29ce64fda165e6e0548fdb0 Mon Sep 17 00:00:00 2001 From: Paul Bakaus Date: Tue, 10 Mar 2026 09:20:23 -0700 Subject: [PATCH] Fix zip downloads by adding _routes.json for Cloudflare Pages Functions Without _routes.json, the SPA fallback was serving index.html instead of invoking the download Functions, causing zip downloads to return HTML. Co-Authored-By: Claude Opus 4.6 --- scripts/build.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/build.js b/scripts/build.js index aafc619e6..6e156de65 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -255,7 +255,16 @@ function generateCFConfig(buildDir) { `; fs.writeFileSync(path.join(buildDir, '_redirects'), redirects); - console.log('✓ Generated Cloudflare Pages config (_headers, _redirects)'); + // _routes.json: tell Cloudflare Pages which paths invoke Functions + // Without this, the SPA fallback serves index.html for function routes + const routes = { + version: 1, + include: ['/api/download/*'], + exclude: [], + }; + fs.writeFileSync(path.join(buildDir, '_routes.json'), JSON.stringify(routes, null, 2)); + + console.log('✓ Generated Cloudflare Pages config (_headers, _redirects, _routes.json)'); } /**