I had problems deploying this blog via cloudflare pages and so I switch to use cloudflare workers. This is a short guide how to setup rspress with cloudflare workers.
1compatibility_date = "2023-10-30"
2main = "src/index.ts" # The entry point for your Workers application
3name = "UNIQUE NAME" # Your project's name
4route = "https://blog.YOURDOMAIN.com/*" # The route to your Workers application
56[build]
7command = "npm run rs.build" # To preview the blog within the cloudflare workers environment,
8# create a npm script to run rspress build
9cwd = "." # Current working directory relative to wrangler.toml
10watch_dir = "./docs" # Your blogposts directory
1112[site]
13bucket = "./doc_build" # Important to create a bucket for the static files
For local development use rspress dev and to preview the blog with cloudflare workers enabled use wrangler dev. To deploy the blog use wrangler deploy.
To handle the static files, we need to create a index.ts file in the src directory. So the cloudflare worker can handle the static files.
src/index.ts
1import{ getAssetFromKV }from'@cloudflare/kv-asset-handler'2// @ts-ignore3import manifestJSON from'__STATIC_CONTENT_MANIFEST'4const assetManifest =JSON.parse(manifestJSON)56exportdefault{7asyncfetch(request, env, ctx){8try{9// Add logic to decide whether to serve an asset or run your original Worker code10returnawaitgetAssetFromKV(11{12 request,13 waitUntil: ctx.waitUntil.bind(ctx)14},15{16ASSET_NAMESPACE: env.__STATIC_CONTENT,17ASSET_MANIFEST: assetManifest
18}19)20}catch(e){21let pathname =newURL(request.url).pathname
22returnnewResponse(`"${pathname}" not found`,{23 status:404,24 statusText:'not found'25})26}27}28}