Cloudflare
Run Mokup on Cloudflare Workers or Pages. Workers are best for API workloads, while Pages works well for static sites plus Functions.
Choose an entry
mokup/server/worker: smallest wrapper, best for direct Worker usage.mokup/server/fetch: manual fetch integration for custom routing.
Workers quick start
When you use mokup/vite, import the virtual bundle generated by Vite:
ts
import { createMokupWorker } from 'mokup/server/worker'
import mokupBundle from 'virtual:mokup-bundle'
export default createMokupWorker(mokupBundle)Wrangler config
jsonc
{
"name": "mokup-worker",
"main": "worker/src/index.ts",
"compatibility_date": "2025-01-15"
}Build & deploy
bash
vite build
wrangler deployPages Functions quick start
Place a function such as functions/[[path]].ts, then call the same fetch handler:
ts
import { createFetchHandler } from 'mokup/server/fetch'
import mokupBundle from 'virtual:mokup-bundle'
const handler = createFetchHandler(mokupBundle)
export const onRequest: PagesFunction = async ({ request }) => {
return (await handler(request)) ?? new Response('Not Found', { status: 404 })
}Also valid (explicit fields):
ts
import { createFetchHandler } from 'mokup/server/fetch'
import mokupBundle from 'virtual:mokup-bundle'
const handler = createFetchHandler({
manifest: mokupBundle.manifest,
moduleMap: mokupBundle.moduleMap,
moduleBase: mokupBundle.moduleBase,
})Build your site and deploy with Pages:
bash
vite build
wrangler pages deploy distMore details
For more deployment-specific options, see Cloudflare Worker.