|
| 1 | +1. [Sign up for Cloudflare](https://www.cloudflare.com/) (they have a free tier) |
| 2 | + |
| 3 | +2. Create a Pages app to host the React client. From the Workers & Pages screen, choose "Create". |
| 4 | +  |
| 5 | + |
| 6 | +3. Select the "Pages" tab and click "Upload assets" from the "Create using direct upload" section. |
| 7 | +  |
| 8 | + |
| 9 | +4. Name your app and click "Create". Note: You do not need to upload any assets and click "Deploy". The Wrangler CLI and GitHub actions will take care of that later. |
| 10 | + |
| 11 | +  |
| 12 | + |
| 13 | +5. Each time you add an app, you will see it appear in your "Workers & Pages" Overview: |
| 14 | +  |
| 15 | + |
| 16 | +6. Add the following variables under "Variables and Secrets" so that the build command can run in the correct environment: |
| 17 | + | Type | Name | Value | |
| 18 | + | --- | --- | --- | |
| 19 | + | Plaintext | NODE_VERSION | 22.9.0 | |
| 20 | + | Plaintext | PNPM_VERSION | 9 | |
| 21 | + |
| 22 | +7. Create a Workers app to host the prod server. From the Workers & Pages Overview page, click "Create" (like step 2), and then from the "Workers" tab, click "Create Worker". |
| 23 | +  |
| 24 | + |
| 25 | +8. Name your worker and click "Deploy". Note: Ignore the `worker.js` code, as it will be overwritten by our app when we run our deploy script. |
| 26 | +  |
| 27 | + |
| 28 | +9. Add a KV namespace for your prod server storage. Navigate to Workers & Pages - KV, and click "Create a namespace". |
| 29 | +  |
| 30 | + |
| 31 | +10. Enter a name for your prod server kv namespace, and click "Add". |
| 32 | +  |
| 33 | + |
| 34 | +11. Repeat steps 7-10 for your stage server and kv storage. Note: It might be useful to use suffix `-stage` in your naming. |
| 35 | + |
| 36 | +12. On the right hand side of the Workers & Pages Overview screen, you can find your Account ID, as well as a link to "Manage API tokens": |
| 37 | +  |
| 38 | + |
| 39 | +13. Create an API token for "Edit Cloudflare Workers", using the provided template. |
| 40 | +  |
| 41 | + |
| 42 | +14. Add your Cloudflare API Token and Account ID in [.env](../.env). This will enable the Wrangler CLI to deploy the app locally. |
| 43 | + |
| 44 | +15. Add your Cloudflare API Token and Account ID to your repository secrets in GitHub. This will enable deploy from GitHub actions. |
| 45 | +  |
| 46 | + |
| 47 | +16. Configure `ENV` and `getServerUrl` in [client/src/config.ts](../client/src/config.ts). Note: This is just a suggestion, and you may choose another method of determining your app's runtime environment. |
| 48 | + |
| 49 | +17. Update [server/wrangler.toml](../server/wrangler.toml) with your app names and IDs. Eg: |
| 50 | + |
| 51 | +```diff |
| 52 | +[env.stage] |
| 53 | +- name = "todo-rename-stage" |
| 54 | ++ name = "my-app-stage" |
| 55 | +workers_dev = true |
| 56 | +- vars = { ALLOWED_HOST = "todo:rename to stage host", ENV = "stage" } |
| 57 | ++ vars = { ALLOWED_HOST = "my-app-stage.pages.dev", ENV = "stage" } |
| 58 | +[[env.stage.kv_namespaces]] |
| 59 | +binding = "DB" |
| 60 | +- id = "e0c5eee53ed34ff69c4d8303f818adca" |
| 61 | ++ id = "fThh47jB971c4GP452h75cP7jqE499mL" |
| 62 | +``` |
| 63 | + |
| 64 | +18. Update the deploy scripts in [client/package.json](../client/package.json) to use your project name. Note: Pages allows a "Preview" branch, for all branches besides main. We use the same app name but provide `--branch "stage"` for our staging branch: |
| 65 | + |
| 66 | +```diff |
| 67 | +- "deploy:stage": "pnpm wrangler pages deploy ./dist --project-name todo-rename --branch \"stage\"..., |
| 68 | ++ "deploy:stage": "pnpm wrangler pages deploy ./dist --project-name my-app --branch \"stage\"..., |
| 69 | +- "deploy:prod": "pnpm wrangler pages deploy ./dist --project-name todo-rename", |
| 70 | ++ "deploy:prod": "pnpm wrangler pages deploy ./dist --project-name my-app", |
| 71 | +``` |
0 commit comments