Unable to deploy Fresh to Cloudflare Workers
Hi, I'm trying to deploy a Fresh project to Cloudflare Workers, but I've been unsuccessful.
Here are the steps I followed:
I created a new project using the following command:
deno run -Ar jsr:@fresh/initI followed the Cloudflare Workers | Fresh docs and added the required code to
vite.config.tsfile.I added a
wrangler.jsoncfile with the following content:{ "$schema": "node_modules/wrangler/config-schema.json", "name": "fresh2-example", "main": "./main.ts", "compatibility_date": "2025-04-01", "compatibility_flags": ["nodejs_compat"], "observability": { "enabled": true }, "upload_source_maps": true }I added the following code to the end of my
main.tsfile:export default { fetch: app.handler(), };I pushed the project to a GitHub repository, which you can find here: mzl980425/fresh2-example. Then, I created a new Worker on Cloudflare and connected it to this repository. The worker's build configuration is as follows:
- Build command:
npx deno task build - Deploy command:
npx wrangler deploy
- Build command:
After the deployment was complete, I found that static assets are served correctly (e.g.,
https://xxx.workers.dev/favicon.ico,https://xxx.workers.dev/logo.svg). However, all other page and API routes return a "NOT FOUND" error, including the root page (https://xxx.workers.dev/) and API routes like (https://xxx.workers.dev/api2/world).
Is there something wrong with my code or configuration? Any help would be greatly appreciated.
Thanks
Source: freshframework/fresh