You can serve a Vite single-page application, HTTP API, and WebSocket endpoint through one development server and one deployed Worker. Keep the existing Worker source and point the frontend's Cloudflare configuration at it:
project/
├── worker/index.ts
└── frontend/
├── package.json
├── index.html
├── vite.config.ts
└── cloudflare.config.tsFrom frontend, install Vite plugin v2 and cf:
npm i -D @cloudflare/vite-plugin@beta cfyarn add -D @cloudflare/vite-plugin@beta cfpnpm add -D @cloudflare/vite-plugin@beta cfbun add -d @cloudflare/vite-plugin@beta cfRun both Vite and cf from that directory so they use the same configuration and Build Output directory.
import { defineConfig } from "vite";
import { cloudflare } from "@cloudflare/vite-plugin";
export default defineConfig({ plugins: [cloudflare()] });import { defineConfig } from "vite";
import { cloudflare } from "@cloudflare/vite-plugin";
export default defineConfig({ plugins: [cloudflare()] });Vite plugin v2 does not read Wrangler configuration. If your Worker uses wrangler.jsonc, migrate it from frontend:
npx cf migrate ../worker/wrangler.jsonc --bundler vite --no-install --force--force lets migration run with the uncommitted setup changes. It does not overwrite an existing cloudflare.config.ts.
The command writes cloudflare.config.ts next to the Wrangler file. Use the generated file as the starting point for frontend/cloudflare.config.ts and update relative paths to work from frontend.
If migration reports that there is no package.json next to the Wrangler file, you do not need to create one: the dependencies are already in frontend/package.json. Resolve any remaining required items before removing the generated error. For details, refer to Migrate a Wrangler project.
Keep your existing Worker's name, compatibility date, and flags, and deploy to the same Cloudflare account. Preserve your bindings in worker.env and Durable Object lifecycle declarations in worker.exports, including class names and storage backends. Keep the Durable Object class exports in the Worker source.
Use this example to set entrypoint and assets in your configuration. The name and compatibility date are examples.
import { defineConfig, defineWorker } from "cf/config";
export default defineConfig({
worker: defineWorker({
name: "full-stack-app",
entrypoint: "../worker/index.ts",
compatibilityDate: "2026-11-30",
assets: {
notFoundHandling: "single-page-application",
runWorkerFirst: ["/api/*", "/ws"],
},
}),
});Keep your existing API and WebSocket handlers. The Worker must handle the WebSocket upgrade at /ws. The runWorkerFirst patterns route requests as follows:
| Request | Handler |
|---|---|
/api/hello |
Worker API handler |
/api/missing |
Worker API handler; return 404 for unknown routes |
/ws |
Worker WebSocket handler |
/settings |
SPA fallback serves index.html |
/api/* does not match bare /api, and /ws does not match /ws/ or paths nested under it. Add patterns for any other paths your Worker handles.
From frontend, run npx cf dev for local development or npx cf deploy to build and deploy. The plugin includes the client assets in Build Output; you do not need a second server or a build-copy step. cloudflare.config.ts has no assets.directory field; the plugin uses Vite's client build output.
For routing rules, refer to Single-page application routing.