chore: Added pages and workers deployment sections f447fd77
Steve · 2025-05-25 00:00 2 file(s) · +203 −2
docs/pages/deployment/client/cloudflare-pages.mdx +85 −1
1 1
# Cloudflare Pages
2 2
3 -
Coming soon
3 +
A great way to host your bhvr client, especially since your server can be hosted with Cloudflare Workers. There are two primary ways you can host your client through Pages:
4 +
- Git Integration
5 +
- Manual Upload
6 +
7 +
::::note
8 +
Once you have chosen one of these methods you will not be able to switch between the two! Doing so will require deleting the site and starting over.
9 +
::::
10 +
11 +
## Git Integration
12 +
13 +
::::steps
14 +
15 +
### Create a New Pages Project
16 +
17 +
Login to your Cloudflare account and then from the sidebar select `Compute (Workers)` and click the `Create` button in the top right. Select the pages tab and then select the Git repository option.
18 +
19 +
### Setup Your Project
20 +
21 +
Connect your choice of Git account and then select the repo for your bhvr project. Once select make sure you have the following items setup accordingly under the build settings:
22 +
23 +
- Framework Preset: `React (Vite)`
24 +
- Build command: `bun install && bun run build`
25 +
- Build output directory: `dist`
26 +
- Root directory (advanced): `client`
27 +
- Environment Variables: `BUN_VERSION=1.2.14` (use the latest version)
28 +
29 +
![dashboard screenshot](https://dweb.mypinata.cloud/ipfs/bafkreicjxhuj6p3kiyg7u6nhoy4z3lvttwka2hxrl5vmrh5ennil6es57q)
30 +
31 +
### Save and Deploy
32 +
33 +
Once you have those settings entered you can just click the "Save and Deploy" button in the bottom right, and you're done! Anytime you push a new commit it will deploy a new version of the site, including previews for branches.
34 +
35 +
::::tip
36 +
[Check out the Cloudflare Docs for more info and tips](https://developers.cloudflare.com/pages/get-started/git-integration/)
37 +
::::
38 +
39 +
40 +
## Direct Upload
41 +
42 +
::::steps
43 +
44 +
### Login to Cloudlfare
45 +
46 +
Using the `wrangler` CLI login to your Cloudflare account to authorize it
47 +
48 +
```bash [!terminal]
49 +
bunx wrangler login
50 +
```
51 +
52 +
### Setup Project
53 +
54 +
First make sure you have built the client
55 +
56 +
```bash [!terminal]
57 +
bun run build
58 +
```
59 +
60 +
Then use the `wrangler` CLI to create a new empty project in Cloudflare
61 +
62 +
```bash [!terminal]
63 +
bunx wrangler pages project create
64 +
```
65 +
66 +
### Deploy
67 +
68 +
Lastly run the following command to directly upload the `dist` build folder of your `client`
69 +
70 +
```bash [!terminal]
71 +
bunx wrangler pages deploy client/dist
72 +
```
73 +
74 +
You can automate this into a script by adding it to your root `package.json`
75 +
76 +
```json
77 +
{
78 +
  "scripts": {
79 +
   // Other scripts
80 +
   "deploy:client": "bun run build:client && bunx wrangler deploy client/dist"
81 +
  }
82 +
}
83 +
```
84 +
85 +
::::tip
86 +
[Check out the Cloudflare Docs for more info and tips](https://developers.cloudflare.com/pages/get-started/direct-upload/)
87 +
::::
docs/pages/deployment/server/cloudflare-workers.mdx +118 −1
1 1
# Cloudflare Workers
2 2
3 -
Coming soon
3 +
One of the simplest ways to deploy your `server` is through Cloudflare Workers, which are lightweight, fast, and very inexpensive.
4 +
5 +
## Deployment
6 +
7 +
::::steps
8 +
9 +
### Login to Cloudlfare
10 +
11 +
Using the `wrangler` CLI login to your Cloudflare account to authorize it
12 +
13 +
```bash [!terminal]
14 +
bunx wrangler login
15 +
```
16 +
17 +
### Add `wrangler.jsonc` File
18 +
19 +
Create a new file called `wrangler.jsonc` in the root of your `server` package and paste in the following template.
20 +
21 +
```jsonc
22 +
{
23 +
  "$schema": "node_modules/wrangler/config-schema.json",
24 +
  "name": "server",
25 +
  "main": "src/index.ts",
26 +
  "compatibility_date": "2025-05-25"
27 +
  // "compatibility_flags": [
28 +
  //   "nodejs_compat"
29 +
  // ],
30 +
  // "vars": {
31 +
  //   "MY_VAR": "my-variable"
32 +
  // },
33 +
  // "kv_namespaces": [
34 +
  //   {
35 +
  //     "binding": "MY_KV_NAMESPACE",
36 +
  //     "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
37 +
  //   }
38 +
  // ],
39 +
  // "r2_buckets": [
40 +
  //   {
41 +
  //     "binding": "MY_BUCKET",
42 +
  //     "bucket_name": "my-bucket"
43 +
  //   }
44 +
  // ],
45 +
  // "d1_databases": [
46 +
  //   {
47 +
  //     "binding": "MY_DB",
48 +
  //     "database_name": "my-database",
49 +
  //     "database_id": ""
50 +
  //   }
51 +
  // ],
52 +
  // "ai": {
53 +
  //   "binding": "AI"
54 +
  // },
55 +
  // "observability": {
56 +
  //   "enabled": true,
57 +
  //   "head_sampling_rate": 1
58 +
  // }
59 +
}
60 +
```
61 +
62 +
### Update `package.json` Files
63 +
64 +
Add the following items to your `server/package.json` file
65 +
66 +
```json
67 +
{
68 +
  "name": "server",
69 +
  "version": "0.0.1",
70 +
  "main": "dist/index.js",
71 +
  "types": "dist/index.d.ts",
72 +
  "scripts": {
73 +
    "build": "tsc",
74 +
    "dev": "bun run --hot src/index.ts", // [!code --]
75 +
    "dev": "wrangler dev", // [!code ++]
76 +
    "deploy": "wrangler deploy --minify", // [!code ++]
77 +
    "cf-typegen": "wrangler types --env-interface CloudflareBindings" // [!code ++]
78 +
  },
79 +
  "dependencies": {
80 +
    "hono": "^4.7.7",
81 +
    "shared": "workspace:*"
82 +
  },
83 +
  "devDependencies": {
84 +
    "@types/bun": "latest",
85 +
    "wrangler": "^4.4.0" // [!code ++]
86 +
  }
87 +
}
88 +
```
89 +
90 +
Then update `scripts` section of the root `package.json` for your bhvr project
91 +
92 +
```json
93 +
"scripts": {
94 +
  "dev:client": "cd client && bun run dev",
95 +
  "dev:server": "cd server && bun run dev",
96 +
  "dev:shared": "cd shared && bun run dev",
97 +
  "dev": "concurrently \"bun run dev:shared\" \"bun run dev:server\" \"bun run dev:client\"",
98 +
  "build:client": "cd client && bun run build",
99 +
  "build:shared": "cd shared && bun run build",
100 +
  "build:server": "cd server && bun run build",
101 +
  "build": "bun run build:shared && bun run build:server && bun run build:client",
102 +
  "deploy:server": "cd server && bun run deploy",
103 +
  "postinstall": "bun run build:shared && bun run build:server"
104 +
},
105 +
```
106 +
107 +
### Deploy
108 +
109 +
Install dependencies for your updated `server/package.json` then run the deploy command
110 +
111 +
```bash [!terminal]
112 +
bun install
113 +
bun run deploy:server
114 +
```
115 +
116 +
::::
117 +
118 +
::::tip
119 +
[Check out the Cloudflare Docs for more info and tips](https://developers.cloudflare.com/workers/)
120 +
::::