Skip to content

Commit 4de3c51

Browse files
committed
Enhance README and CLI for improved deployment options. Added support for deploying static files to Cloudflare Pages, including new command-line options and examples. Updated deployment instructions to clarify the one-shot deployment process and the benefits of using Cloudflare Pages. Improved error handling and user guidance in the CLI for better usability.
1 parent 2fe60ab commit 4de3c51

6 files changed

Lines changed: 1331 additions & 70 deletions

File tree

README.md

Lines changed: 143 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,39 +111,93 @@ that would use the dev URL from `.env.local`.
111111
npx @get-convex/self-static-hosting upload [options]
112112

113113
Options:
114-
-d, --dist <path> Path to dist directory (default: ./dist)
115-
-c, --component <name> Convex component name (default: staticHosting)
116-
--prod Deploy to production Convex deployment
117-
--dev Deploy to dev deployment (default)
118-
-b, --build Run 'npm run build' with correct VITE_CONVEX_URL
119-
--domain <name> Custom domain for URL output and Cloudflare cache purge
120-
-h, --help Show help
114+
-d, --dist <path> Path to dist directory (default: ./dist)
115+
-c, --component <name> Convex component name (default: staticHosting)
116+
--prod Deploy to production Convex deployment
117+
--dev Deploy to dev deployment (default)
118+
-b, --build Run 'npm run build' with correct VITE_CONVEX_URL
119+
--domain <name> Custom domain for URL output and Cloudflare cache purge
120+
--cloudflare-pages Deploy to Cloudflare Pages instead of Convex storage
121+
--pages-project <name> Cloudflare Pages project name
122+
-h, --help Show help
121123
```
122124

123125
**Examples:**
124126

125127
```bash
126-
# Deploy to production with automatic build
128+
# Deploy to production with automatic build (Convex storage)
127129
npx @get-convex/self-static-hosting upload --build --prod
128130

129131
# Deploy to production with custom domain (also purges Cloudflare cache)
130132
npx @get-convex/self-static-hosting upload --build --prod --domain mysite.com
131133

134+
# Deploy to Cloudflare Pages instead
135+
npx @get-convex/self-static-hosting upload --build --prod --cloudflare-pages --pages-project my-app
136+
132137
# Deploy to dev (for testing)
133138
npx @get-convex/self-static-hosting upload --build
134139
```
135140

136141
## Deployment
137142

143+
### One-Shot Deployment (Recommended)
144+
145+
Deploy both Convex backend and static files with a single command:
146+
138147
```bash
139-
# Make sure you're logged in to Convex
148+
# Make sure you're logged in
140149
npx convex login
150+
npx wrangler login # if using Cloudflare Pages
151+
152+
# Deploy everything to Cloudflare Pages
153+
npx @get-convex/self-static-hosting deploy --cloudflare-pages --pages-project my-app
154+
155+
# Or deploy everything to Convex storage
156+
npx @get-convex/self-static-hosting deploy
157+
```
158+
159+
The `deploy` command:
160+
1. Builds frontend with production `VITE_CONVEX_URL`
161+
2. Deploys Convex backend (`npx convex deploy`)
162+
3. Deploys static files (to CF Pages or Convex storage)
163+
164+
This minimizes the inconsistency window between backend and frontend updates.
165+
166+
**Deploy command options:**
167+
168+
```bash
169+
npx @get-convex/self-static-hosting deploy [options]
170+
171+
Options:
172+
-d, --dist <path> Path to dist directory (default: ./dist)
173+
-c, --component <name> Convex component name (default: staticHosting)
174+
--cloudflare-pages Deploy static files to Cloudflare Pages
175+
--pages-project <name> Cloudflare Pages project name
176+
--skip-build Skip the build step (use existing dist)
177+
--skip-convex Skip Convex backend deployment
178+
-h, --help Show help
179+
```
141180

142-
# Deploy your Convex backend to production first
181+
Add to `package.json` for easy deployments:
182+
183+
```json
184+
{
185+
"scripts": {
186+
"deploy": "npx @get-convex/self-static-hosting deploy --cloudflare-pages --pages-project my-app"
187+
}
188+
}
189+
```
190+
191+
### Manual Two-Step Deployment
192+
193+
If you prefer more control, deploy separately:
194+
195+
```bash
196+
# Deploy Convex backend
143197
npx convex deploy
144198

145-
# Deploy static files to production
146-
npm run deploy:static
199+
# Deploy static files
200+
npx @get-convex/self-static-hosting upload --build --prod
147201
```
148202

149203
Your app is now live at `https://your-deployment.convex.site`
@@ -171,18 +225,90 @@ The upload API uses **internal functions** that can only be called via:
171225
This means unauthorized users **cannot** upload files to your site, even if they
172226
know your Convex URL.
173227

174-
## CDN Setup (Cloudflare)
228+
## Cloudflare Pages (Recommended)
229+
230+
Deploy your static files directly to Cloudflare Pages for the best performance.
231+
Files are served from Cloudflare's edge network without needing Convex storage.
232+
233+
### Benefits
234+
235+
- Files served directly from Cloudflare edge (no origin fetch)
236+
- No Convex storage costs for static assets
237+
- No Worker proxy needed
238+
- Built-in SPA routing support
239+
- Automatic SSL/HTTPS
240+
241+
### Quick Setup
242+
243+
```bash
244+
npx @get-convex/self-static-hosting setup-cloudflare
245+
```
246+
247+
The wizard will ask you to choose between:
248+
1. **Cloudflare Pages** (recommended) - Files hosted on CF edge
249+
2. **Convex Storage + Cloudflare CDN** - Files in Convex, cached by CF
250+
251+
For Cloudflare Pages, the wizard will:
252+
1. Login to Cloudflare (via wrangler)
253+
2. Create a Pages project (or use existing)
254+
3. Optionally configure a custom domain
255+
4. Save configuration to `.env.local`
256+
5. Offer to build and deploy
257+
258+
### Manual Setup
259+
260+
1. Login to Cloudflare:
261+
```bash
262+
npx wrangler login
263+
```
264+
265+
2. Deploy to Cloudflare Pages:
266+
```bash
267+
npx @get-convex/self-static-hosting upload --build --prod \
268+
--cloudflare-pages --pages-project my-app
269+
```
270+
271+
3. Add to `package.json`:
272+
```json
273+
{
274+
"scripts": {
275+
"deploy:static": "npx @get-convex/self-static-hosting upload --build --prod --cloudflare-pages"
276+
}
277+
}
278+
```
279+
280+
4. Set environment variable (optional, alternative to `--pages-project`):
281+
```bash
282+
export CLOUDFLARE_PAGES_PROJECT=my-app
283+
```
284+
285+
### Custom Domains
286+
287+
Add custom domains in the Cloudflare dashboard:
288+
- Go to Workers & Pages → your project → Custom domains → Add
289+
290+
Or use the setup wizard which can configure this for you.
291+
292+
### Live Reload
293+
294+
The live reload feature still works with Cloudflare Pages! The CLI updates
295+
Convex deployment info after each deploy, so connected clients get notified.
296+
297+
---
298+
299+
## CDN Setup (Convex Storage + Cloudflare)
175300

176-
For production deployments, put Cloudflare in front of your Convex static site
177-
for edge caching, compression, DDoS protection, and custom domains.
301+
If you prefer to keep static files in Convex storage (instead of Cloudflare
302+
Pages), you can put Cloudflare in front as a CDN for edge caching, compression,
303+
DDoS protection, and custom domains.
178304

179-
### Quick Setup (Recommended)
305+
### Quick Setup
180306

181307
```bash
182308
npx @get-convex/self-static-hosting setup-cloudflare
183309
```
184310

185-
This interactive wizard will:
311+
Select option 2 (Convex Storage + Cloudflare CDN). The wizard will:
186312

187313
1. Login to Cloudflare (via wrangler)
188314
2. Let you select or add a domain

0 commit comments

Comments
 (0)