@@ -87,16 +87,21 @@ export default http;
8787{
8888 "scripts": {
8989 "build": "vite build",
90- "deploy:static": "npm run build && npx @get-convex/self-static-hosting upload"
90+ "deploy:static": "npx @get-convex/self-static-hosting upload --build --prod "
9191 }
9292}
9393\`\`\`
9494
95- If using a path prefix, specify the component:
95+ IMPORTANT: Use \`--build\` flag instead of running \`npm run build\` separately.
96+ The \`--build\` flag ensures \`VITE_CONVEX_URL\` is set correctly for the target
97+ environment (production or dev). Running build separately uses .env.local which
98+ has the dev URL.
99+
100+ For custom domains with Cloudflare:
96101\`\`\`json
97102{
98103 "scripts": {
99- "deploy:static": "npm run build && npx @get-convex/self-static-hosting upload --component staticHosting "
104+ "deploy:static": "npx @get-convex/self-static-hosting upload --build --prod --domain yourdomain.com "
100105 }
101106}
102107\`\`\`
@@ -143,42 +148,94 @@ function App() {
143148# Login to Convex (first time)
144149npx convex login
145150
146- # Push Convex functions
147- npx convex dev --once
151+ # Deploy Convex backend to production FIRST
152+ npx convex deploy
148153
149- # Build and deploy static files
154+ # Deploy static files to production
150155npm run deploy:static
151156
152157# Your app is now live at:
153158# https://your-deployment.convex.site
154159# (or https://your-deployment.convex.site/app/ if using path prefix)
155160\`\`\`
156161
157- ## Optional: Cloudflare CDN
162+ For development/testing:
163+ \`\`\`bash
164+ # Push to dev environment
165+ npx convex dev --once
166+
167+ # Deploy static files to dev (omit --prod)
168+ npx @get-convex/self-static-hosting upload --build
169+ \`\`\`
170+
171+ ## Optional: Cloudflare CDN with Custom Domain
172+
173+ For production with a custom domain, edge caching, and DDoS protection.
158174
159- For production with custom domain and edge caching:
175+ ### Quick Setup (Recommended)
176+
177+ Run the interactive wizard:
160178
161179\`\`\`bash
162- # Login to Cloudflare
163- npx wrangler login
180+ npx @get-convex/self-static-hosting setup-cloudflare
181+ \`\`\`
164182
165- # Deploy with automatic cache purge
166- npx @get-convex/self-static-hosting upload --domain yourdomain.com
183+ This wizard will:
184+ 1. Login to Cloudflare (via wrangler)
185+ 2. Let you select or add a domain
186+ 3. Detect your production Convex deployment URL
187+ 4. Configure DNS (CNAME pointing to your Convex site)
188+ 5. Deploy a Cloudflare Worker to handle Host header rewriting
189+ 6. Set SSL/TLS mode to "Full" (prevents redirect loops)
190+ 7. Set up cache purge credentials
191+ 8. Offer to deploy your Convex backend and static files
192+
193+ After setup, deploy with:
194+ \`\`\`bash
195+ npm run deploy:static
167196\`\`\`
168197
169- Or for CI/CD, set environment variables:
198+ The Cloudflare cache is automatically purged on each deploy.
199+
200+ ### Manual Cloudflare Setup
201+
202+ If you prefer manual setup:
203+
204+ 1. Add your domain to Cloudflare
205+ 2. Create a CNAME record pointing to your-deployment.convex.site
206+ 3. Deploy a Cloudflare Worker to rewrite the Host header (required!)
207+ 4. Set SSL/TLS mode to "Full" (not "Flexible")
208+
209+ For CI/CD, set environment variables:
170210\`\`\`bash
171211export CLOUDFLARE_ZONE_ID="your-zone-id"
172212export CLOUDFLARE_API_TOKEN="your-api-token"
173213npm run deploy:static
174214\`\`\`
175215
216+ ## CLI Reference
217+
218+ \`\`\`bash
219+ npx @get-convex/self-static-hosting upload [options]
220+
221+ Options:
222+ -d, --dist <path> Path to dist directory (default: ./dist)
223+ -c, --component <name> Convex component name (default: staticHosting)
224+ --prod Deploy to production Convex deployment
225+ --dev Deploy to dev deployment (default)
226+ -b, --build Run 'npm run build' with correct VITE_CONVEX_URL
227+ --domain <name> Custom domain for URL output and cache purge
228+ -h, --help Show help
229+ \`\`\`
230+
176231## Important Notes
177232
1782331. The upload functions are INTERNAL - they can only be called via \`npx convex run\`, not from the public internet
1792342. Static files are stored in the app's storage (not the component's) for proper isolation
1802353. Hashed assets (e.g., main-abc123.js) get immutable caching; HTML files always revalidate
1812364. The component supports SPA routing - routes without file extensions serve index.html
237+ 5. Always use \`--build\` flag to ensure VITE_CONVEX_URL is set correctly for the target environment
238+ 6. Deploy Convex backend (\`npx convex deploy\`) BEFORE deploying static files to production
182239` ;
183240
184241console . log ( instructions ) ;
0 commit comments