Skip to content

Commit 8b99cf9

Browse files
author
Seth Raphael
committed
Update README and CLI to streamline deployment process. Changed installation instructions to use GitHub repository directly, emphasized the use of --build flag for production deployments, and clarified Cloudflare setup steps. Enhanced error messages in the CLI for better user guidance and added new command-line options for improved functionality.
1 parent 0be76da commit 8b99cf9

4 files changed

Lines changed: 81 additions & 18 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ HTTP actions and file storage. No external hosting provider required!
2323
Install the component:
2424

2525
```bash
26-
npm install @get-convex/self-static-hosting
26+
npm install github:get-convex/self-static-hosting#main
2727
```
2828

2929
### Quick Start with LLM

src/cli/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function printInitInstructions() {
7171
## 1. Install the component
7272
7373
\`\`\`bash
74-
npm install @get-convex/self-static-hosting
74+
npm install github:get-convex/self-static-hosting#main
7575
\`\`\`
7676
7777
## 2. Add to convex.config.ts

src/cli/init.ts

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
144149
npx 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
150155
npm 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
171211
export CLOUDFLARE_ZONE_ID="your-zone-id"
172212
export CLOUDFLARE_API_TOKEN="your-api-token"
173213
npm 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
178233
1. The upload functions are INTERNAL - they can only be called via \`npx convex run\`, not from the public internet
179234
2. Static files are stored in the app's storage (not the component's) for proper isolation
180235
3. Hashed assets (e.g., main-abc123.js) get immutable caching; HTML files always revalidate
181236
4. 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

184241
console.log(instructions);

src/cli/upload.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ async function main(): Promise<void> {
313313
}
314314
} catch {
315315
console.error("Could not get production Convex URL.");
316-
console.error("Make sure you have deployed to production: npx convex deploy");
316+
console.error(
317+
"Make sure you have deployed to production: npx convex deploy",
318+
);
317319
process.exit(1);
318320
}
319321
} else {
@@ -355,7 +357,9 @@ async function main(): Promise<void> {
355357

356358
if (!existsSync(distDir)) {
357359
console.error(`Error: dist directory not found: ${distDir}`);
358-
console.error("Run your build command first (e.g., 'npm run build' or add --build flag)");
360+
console.error(
361+
"Run your build command first (e.g., 'npm run build' or add --build flag)",
362+
);
359363
process.exit(1);
360364
}
361365

@@ -503,7 +507,9 @@ async function main(): Promise<void> {
503507

504508
if (!cachePurged && !args.domain) {
505509
console.log("");
506-
console.log("💡 Tip: Add --domain yoursite.com to auto-purge Cloudflare cache");
510+
console.log(
511+
"💡 Tip: Add --domain yoursite.com to auto-purge Cloudflare cache",
512+
);
507513
console.log(" (requires 'npx wrangler login' or CLOUDFLARE_API_TOKEN)");
508514
}
509515
}

0 commit comments

Comments
 (0)