@convex-dev/static-hosting 0.1.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +333 -0
- package/dist/cli/deploy.d.ts +16 -0
- package/dist/cli/deploy.d.ts.map +1 -0
- package/dist/cli/deploy.js +324 -0
- package/dist/cli/deploy.js.map +1 -0
- package/dist/cli/index.d.ts +15 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +95 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +9 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +181 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/next-build.d.ts +24 -0
- package/dist/cli/next-build.d.ts.map +1 -0
- package/dist/cli/next-build.js +569 -0
- package/dist/cli/next-build.js.map +1 -0
- package/dist/cli/setup.d.ts +9 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +157 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli/upload.d.ts +15 -0
- package/dist/cli/upload.d.ts.map +1 -0
- package/dist/cli/upload.js +436 -0
- package/dist/cli/upload.js.map +1 -0
- package/dist/client/_generated/_ignore.d.ts +1 -0
- package/dist/client/_generated/_ignore.d.ts.map +1 -0
- package/dist/client/_generated/_ignore.js +3 -0
- package/dist/client/_generated/_ignore.js.map +1 -0
- package/dist/client/index.d.ts +142 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +475 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/next.d.ts +38 -0
- package/dist/client/next.d.ts.map +1 -0
- package/dist/client/next.js +175 -0
- package/dist/client/next.js.map +1 -0
- package/dist/client/nextAdapter.d.ts +4 -0
- package/dist/client/nextAdapter.d.ts.map +1 -0
- package/dist/client/nextAdapter.js +9 -0
- package/dist/client/nextAdapter.js.map +1 -0
- package/dist/component/_generated/api.d.ts +34 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +73 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +3 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/lib.d.ts +88 -0
- package/dist/component/lib.d.ts.map +1 -0
- package/dist/component/lib.js +210 -0
- package/dist/component/lib.js.map +1 -0
- package/dist/component/schema.d.ts +27 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +20 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/react/index.d.ts +80 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +138 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +120 -0
- package/src/cli/deploy.ts +375 -0
- package/src/cli/index.ts +104 -0
- package/src/cli/init.ts +181 -0
- package/src/cli/next-build.ts +707 -0
- package/src/cli/setup.ts +190 -0
- package/src/cli/upload.ts +521 -0
- package/src/client/_generated/_ignore.ts +1 -0
- package/src/client/index.test.ts +67 -0
- package/src/client/index.ts +553 -0
- package/src/client/next.ts +223 -0
- package/src/client/nextAdapter.ts +17 -0
- package/src/client/setup.test.ts +26 -0
- package/src/component/_generated/api.ts +50 -0
- package/src/component/_generated/component.ts +104 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +161 -0
- package/src/component/convex.config.ts +3 -0
- package/src/component/lib.test.ts +110 -0
- package/src/component/lib.ts +228 -0
- package/src/component/schema.ts +21 -0
- package/src/component/setup.test.ts +11 -0
- package/src/react/index.tsx +184 -0
- package/src/test.ts +18 -0
package/src/cli/init.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Output integration instructions for LLMs.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* npx @convex-dev/static-hosting init
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const instructions = `
|
|
10
|
+
# Convex Static Hosting - Integration Instructions
|
|
11
|
+
|
|
12
|
+
You are integrating the @convex-dev/static-hosting component into a Convex app.
|
|
13
|
+
This component enables hosting static files (React/Vite apps) directly on Convex.
|
|
14
|
+
|
|
15
|
+
## What This Component Does
|
|
16
|
+
|
|
17
|
+
- Stores static files in Convex storage
|
|
18
|
+
- Serves files via HTTP actions with proper MIME types
|
|
19
|
+
- Supports SPA routing (fallback to index.html)
|
|
20
|
+
- Smart caching: hashed assets cached forever, HTML revalidates
|
|
21
|
+
- ETag support for efficient cache revalidation
|
|
22
|
+
- Live reload notifications when new deployments happen
|
|
23
|
+
|
|
24
|
+
## Files to Create/Modify
|
|
25
|
+
|
|
26
|
+
### 1. convex/convex.config.ts (create or modify)
|
|
27
|
+
|
|
28
|
+
\`\`\`typescript
|
|
29
|
+
import { defineApp } from "convex/server";
|
|
30
|
+
import staticHosting from "@convex-dev/static-hosting/convex.config";
|
|
31
|
+
|
|
32
|
+
const app = defineApp();
|
|
33
|
+
app.use(staticHosting);
|
|
34
|
+
|
|
35
|
+
export default app;
|
|
36
|
+
\`\`\`
|
|
37
|
+
|
|
38
|
+
### 2. convex/staticHosting.ts (create)
|
|
39
|
+
|
|
40
|
+
\`\`\`typescript
|
|
41
|
+
import { components } from "./_generated/api";
|
|
42
|
+
import {
|
|
43
|
+
exposeUploadApi,
|
|
44
|
+
exposeDeploymentQuery,
|
|
45
|
+
} from "@convex-dev/static-hosting";
|
|
46
|
+
|
|
47
|
+
// Internal functions for secure uploads (only callable via CLI)
|
|
48
|
+
export const { generateUploadUrl, recordAsset, gcOldAssets, listAssets } =
|
|
49
|
+
exposeUploadApi(components.staticHosting);
|
|
50
|
+
|
|
51
|
+
// Public query for live reload notifications
|
|
52
|
+
export const { getCurrentDeployment } =
|
|
53
|
+
exposeDeploymentQuery(components.staticHosting);
|
|
54
|
+
\`\`\`
|
|
55
|
+
|
|
56
|
+
### 3. convex/http.ts (create or modify)
|
|
57
|
+
|
|
58
|
+
\`\`\`typescript
|
|
59
|
+
import { httpRouter } from "convex/server";
|
|
60
|
+
import { registerStaticRoutes } from "@convex-dev/static-hosting";
|
|
61
|
+
import { components } from "./_generated/api";
|
|
62
|
+
|
|
63
|
+
const http = httpRouter();
|
|
64
|
+
|
|
65
|
+
// Option A: Serve at root (if no other HTTP routes)
|
|
66
|
+
registerStaticRoutes(http, components.staticHosting);
|
|
67
|
+
|
|
68
|
+
// Option B: Serve at /app/ prefix (recommended if you have API routes)
|
|
69
|
+
// registerStaticRoutes(http, components.staticHosting, {
|
|
70
|
+
// pathPrefix: "/app",
|
|
71
|
+
// });
|
|
72
|
+
|
|
73
|
+
// Add other HTTP routes here if needed
|
|
74
|
+
// http.route({ path: "/api/webhook", method: "POST", handler: ... });
|
|
75
|
+
|
|
76
|
+
export default http;
|
|
77
|
+
\`\`\`
|
|
78
|
+
|
|
79
|
+
### 4. package.json scripts (add)
|
|
80
|
+
|
|
81
|
+
\`\`\`json
|
|
82
|
+
{
|
|
83
|
+
"scripts": {
|
|
84
|
+
"build": "vite build",
|
|
85
|
+
"deploy:static": "npx @convex-dev/static-hosting upload --build --prod"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
\`\`\`
|
|
89
|
+
|
|
90
|
+
IMPORTANT: Use \`--build\` flag instead of running \`npm run build\` separately.
|
|
91
|
+
The \`--build\` flag ensures \`VITE_CONVEX_URL\` is set correctly for the target
|
|
92
|
+
environment (production or dev). Running build separately uses .env.local which
|
|
93
|
+
has the dev URL.
|
|
94
|
+
|
|
95
|
+
### 5. src/App.tsx (optional: add live reload banner)
|
|
96
|
+
|
|
97
|
+
\`\`\`typescript
|
|
98
|
+
import { UpdateBanner } from "@convex-dev/static-hosting/react";
|
|
99
|
+
import { api } from "../convex/_generated/api";
|
|
100
|
+
|
|
101
|
+
function App() {
|
|
102
|
+
return (
|
|
103
|
+
<div>
|
|
104
|
+
{/* Shows banner when new deployment is available */}
|
|
105
|
+
<UpdateBanner
|
|
106
|
+
getCurrentDeployment={api.staticHosting.getCurrentDeployment}
|
|
107
|
+
message="New version available!"
|
|
108
|
+
buttonText="Refresh"
|
|
109
|
+
/>
|
|
110
|
+
|
|
111
|
+
{/* Rest of your app */}
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
\`\`\`
|
|
116
|
+
|
|
117
|
+
Or use the hook for custom UI:
|
|
118
|
+
\`\`\`typescript
|
|
119
|
+
import { useDeploymentUpdates } from "@convex-dev/static-hosting/react";
|
|
120
|
+
import { api } from "../convex/_generated/api";
|
|
121
|
+
|
|
122
|
+
function App() {
|
|
123
|
+
const { updateAvailable, reload, dismiss } = useDeploymentUpdates(
|
|
124
|
+
api.staticHosting.getCurrentDeployment
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
// Custom update notification UI
|
|
128
|
+
}
|
|
129
|
+
\`\`\`
|
|
130
|
+
|
|
131
|
+
## Deployment
|
|
132
|
+
|
|
133
|
+
\`\`\`bash
|
|
134
|
+
# Login to Convex (first time)
|
|
135
|
+
npx convex login
|
|
136
|
+
|
|
137
|
+
# Deploy Convex backend to production FIRST
|
|
138
|
+
npx convex deploy
|
|
139
|
+
|
|
140
|
+
# Deploy static files to production
|
|
141
|
+
npm run deploy:static
|
|
142
|
+
|
|
143
|
+
# Your app is now live at:
|
|
144
|
+
# https://your-deployment.convex.site
|
|
145
|
+
# (or https://your-deployment.convex.site/app/ if using path prefix)
|
|
146
|
+
\`\`\`
|
|
147
|
+
|
|
148
|
+
For development/testing:
|
|
149
|
+
\`\`\`bash
|
|
150
|
+
# Push to dev environment
|
|
151
|
+
npx convex dev --once
|
|
152
|
+
|
|
153
|
+
# Deploy static files to dev (omit --prod)
|
|
154
|
+
npx @convex-dev/static-hosting upload --build
|
|
155
|
+
\`\`\`
|
|
156
|
+
|
|
157
|
+
## CLI Reference
|
|
158
|
+
|
|
159
|
+
\`\`\`bash
|
|
160
|
+
npx @convex-dev/static-hosting upload [options]
|
|
161
|
+
|
|
162
|
+
Options:
|
|
163
|
+
-d, --dist <path> Path to dist directory (default: ./dist)
|
|
164
|
+
-c, --component <name> Convex component name (default: staticHosting)
|
|
165
|
+
--prod Deploy to production Convex deployment
|
|
166
|
+
--dev Deploy to dev deployment (default)
|
|
167
|
+
-b, --build Run 'npm run build' with correct VITE_CONVEX_URL
|
|
168
|
+
-h, --help Show help
|
|
169
|
+
\`\`\`
|
|
170
|
+
|
|
171
|
+
## Important Notes
|
|
172
|
+
|
|
173
|
+
1. The upload functions are INTERNAL - they can only be called via \`npx convex run\`, not from the public internet
|
|
174
|
+
2. Static files are stored in the app's storage (not the component's) for proper isolation
|
|
175
|
+
3. Hashed assets (e.g., main-abc123.js) get immutable caching; HTML files always revalidate
|
|
176
|
+
4. The component supports SPA routing - routes without file extensions serve index.html
|
|
177
|
+
5. Always use \`--build\` flag to ensure VITE_CONVEX_URL is set correctly for the target environment
|
|
178
|
+
6. Deploy Convex backend (\`npx convex deploy\`) BEFORE deploying static files to production
|
|
179
|
+
`;
|
|
180
|
+
|
|
181
|
+
console.log(instructions);
|