From 11167e48f312f7d888ef2f828fedf9508b3f3d03 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 4 May 2026 00:57:28 +0000 Subject: [PATCH] refactor: migrate web app to Workers + Static Assets format The Cloudflare project was created as a Workers Build (the new unified format), so the legacy Pages config (pages_build_output_dir, functions/api/[[path]].ts) does not deploy. Switch to the modern shape: a worker entry point that delegates to the Hono app for /api/* and falls through to the [assets] binding for everything else, with SPA fallback for client-side routes. Build output (apps/web/dist) and bindings (D1, R2, env vars) are unchanged. https://claude.ai/code/session_01TPBqgcSJMppgrpiq7fLywL --- apps/web/functions/api/[[path]].ts | 7 ------- apps/web/package.json | 4 ++-- apps/web/src/worker.ts | 18 ++++++++++++++++++ apps/web/wrangler.toml | 12 +++++++++--- 4 files changed, 29 insertions(+), 12 deletions(-) delete mode 100644 apps/web/functions/api/[[path]].ts create mode 100644 apps/web/src/worker.ts diff --git a/apps/web/functions/api/[[path]].ts b/apps/web/functions/api/[[path]].ts deleted file mode 100644 index 4d16550..0000000 --- a/apps/web/functions/api/[[path]].ts +++ /dev/null @@ -1,7 +0,0 @@ -import { createApp } from '@leetete/api'; -import type { AppEnv } from '@leetete/api/env'; - -const app = createApp(); - -export const onRequest: PagesFunction = (ctx) => - app.fetch(ctx.request, ctx.env, ctx as unknown as ExecutionContext); diff --git a/apps/web/package.json b/apps/web/package.json index 7925329..9f21915 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -8,8 +8,8 @@ "build": "tsc --noEmit && vite build", "preview": "vite preview", "typecheck": "tsc --noEmit", - "deploy": "wrangler pages deploy dist --project-name stefanieeleandro", - "pages:dev": "wrangler pages dev dist --compatibility-flags=nodejs_compat" + "deploy": "wrangler deploy", + "pages:dev": "wrangler dev" }, "dependencies": { "@leetete/api": "workspace:*", diff --git a/apps/web/src/worker.ts b/apps/web/src/worker.ts new file mode 100644 index 0000000..cd4ee02 --- /dev/null +++ b/apps/web/src/worker.ts @@ -0,0 +1,18 @@ +import { createApp } from '@leetete/api'; +import type { AppEnv } from '@leetete/api/env'; + +const app = createApp(); + +export interface Env extends AppEnv { + ASSETS: Fetcher; +} + +export default { + async fetch(req, env, ctx) { + const url = new URL(req.url); + if (url.pathname.startsWith('/api/')) { + return app.fetch(req, env, ctx); + } + return env.ASSETS.fetch(req); + }, +} satisfies ExportedHandler; diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml index f2be782..9e2cddd 100644 --- a/apps/web/wrangler.toml +++ b/apps/web/wrangler.toml @@ -1,7 +1,13 @@ name = "stefanieeleandro" +main = "src/worker.ts" compatibility_date = "2026-04-01" compatibility_flags = ["nodejs_compat"] -pages_build_output_dir = "dist" + +[assets] +directory = "./dist" +binding = "ASSETS" +not_found_handling = "single-page-application" +run_worker_first = ["/api/*"] [[d1_databases]] binding = "DB" @@ -20,9 +26,9 @@ S3_REGION = "auto" S3_BUCKET = "wedding-media" S3_FORCE_PATH_STYLE = "false" # S3_ENDPOINT, S3_PUBLIC_BASE_URL, CF_ACCESS_TEAM, CF_ACCESS_AUD are -# set after Cloudflare config (see README of deploy steps). +# set after Cloudflare config (see deploy notes). # -# Secrets (set via `wrangler pages secret put --project-name stefanieeleandro`): +# Secrets (set via `wrangler secret put ` or via the dashboard): # S3_ACCESS_KEY_ID # S3_SECRET_ACCESS_KEY # TURNSTILE_SECRET