@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.
Files changed (98) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +333 -0
  3. package/dist/cli/deploy.d.ts +16 -0
  4. package/dist/cli/deploy.d.ts.map +1 -0
  5. package/dist/cli/deploy.js +324 -0
  6. package/dist/cli/deploy.js.map +1 -0
  7. package/dist/cli/index.d.ts +15 -0
  8. package/dist/cli/index.d.ts.map +1 -0
  9. package/dist/cli/index.js +95 -0
  10. package/dist/cli/index.js.map +1 -0
  11. package/dist/cli/init.d.ts +9 -0
  12. package/dist/cli/init.d.ts.map +1 -0
  13. package/dist/cli/init.js +181 -0
  14. package/dist/cli/init.js.map +1 -0
  15. package/dist/cli/next-build.d.ts +24 -0
  16. package/dist/cli/next-build.d.ts.map +1 -0
  17. package/dist/cli/next-build.js +569 -0
  18. package/dist/cli/next-build.js.map +1 -0
  19. package/dist/cli/setup.d.ts +9 -0
  20. package/dist/cli/setup.d.ts.map +1 -0
  21. package/dist/cli/setup.js +157 -0
  22. package/dist/cli/setup.js.map +1 -0
  23. package/dist/cli/upload.d.ts +15 -0
  24. package/dist/cli/upload.d.ts.map +1 -0
  25. package/dist/cli/upload.js +436 -0
  26. package/dist/cli/upload.js.map +1 -0
  27. package/dist/client/_generated/_ignore.d.ts +1 -0
  28. package/dist/client/_generated/_ignore.d.ts.map +1 -0
  29. package/dist/client/_generated/_ignore.js +3 -0
  30. package/dist/client/_generated/_ignore.js.map +1 -0
  31. package/dist/client/index.d.ts +142 -0
  32. package/dist/client/index.d.ts.map +1 -0
  33. package/dist/client/index.js +475 -0
  34. package/dist/client/index.js.map +1 -0
  35. package/dist/client/next.d.ts +38 -0
  36. package/dist/client/next.d.ts.map +1 -0
  37. package/dist/client/next.js +175 -0
  38. package/dist/client/next.js.map +1 -0
  39. package/dist/client/nextAdapter.d.ts +4 -0
  40. package/dist/client/nextAdapter.d.ts.map +1 -0
  41. package/dist/client/nextAdapter.js +9 -0
  42. package/dist/client/nextAdapter.js.map +1 -0
  43. package/dist/component/_generated/api.d.ts +34 -0
  44. package/dist/component/_generated/api.d.ts.map +1 -0
  45. package/dist/component/_generated/api.js +31 -0
  46. package/dist/component/_generated/api.js.map +1 -0
  47. package/dist/component/_generated/component.d.ts +73 -0
  48. package/dist/component/_generated/component.d.ts.map +1 -0
  49. package/dist/component/_generated/component.js +11 -0
  50. package/dist/component/_generated/component.js.map +1 -0
  51. package/dist/component/_generated/dataModel.d.ts +46 -0
  52. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  53. package/dist/component/_generated/dataModel.js +11 -0
  54. package/dist/component/_generated/dataModel.js.map +1 -0
  55. package/dist/component/_generated/server.d.ts +121 -0
  56. package/dist/component/_generated/server.d.ts.map +1 -0
  57. package/dist/component/_generated/server.js +78 -0
  58. package/dist/component/_generated/server.js.map +1 -0
  59. package/dist/component/convex.config.d.ts +3 -0
  60. package/dist/component/convex.config.d.ts.map +1 -0
  61. package/dist/component/convex.config.js +3 -0
  62. package/dist/component/convex.config.js.map +1 -0
  63. package/dist/component/lib.d.ts +88 -0
  64. package/dist/component/lib.d.ts.map +1 -0
  65. package/dist/component/lib.js +210 -0
  66. package/dist/component/lib.js.map +1 -0
  67. package/dist/component/schema.d.ts +27 -0
  68. package/dist/component/schema.d.ts.map +1 -0
  69. package/dist/component/schema.js +20 -0
  70. package/dist/component/schema.js.map +1 -0
  71. package/dist/react/index.d.ts +80 -0
  72. package/dist/react/index.d.ts.map +1 -0
  73. package/dist/react/index.js +138 -0
  74. package/dist/react/index.js.map +1 -0
  75. package/package.json +120 -0
  76. package/src/cli/deploy.ts +375 -0
  77. package/src/cli/index.ts +104 -0
  78. package/src/cli/init.ts +181 -0
  79. package/src/cli/next-build.ts +707 -0
  80. package/src/cli/setup.ts +190 -0
  81. package/src/cli/upload.ts +521 -0
  82. package/src/client/_generated/_ignore.ts +1 -0
  83. package/src/client/index.test.ts +67 -0
  84. package/src/client/index.ts +553 -0
  85. package/src/client/next.ts +223 -0
  86. package/src/client/nextAdapter.ts +17 -0
  87. package/src/client/setup.test.ts +26 -0
  88. package/src/component/_generated/api.ts +50 -0
  89. package/src/component/_generated/component.ts +104 -0
  90. package/src/component/_generated/dataModel.ts +60 -0
  91. package/src/component/_generated/server.ts +161 -0
  92. package/src/component/convex.config.ts +3 -0
  93. package/src/component/lib.test.ts +110 -0
  94. package/src/component/lib.ts +228 -0
  95. package/src/component/schema.ts +21 -0
  96. package/src/component/setup.test.ts +11 -0
  97. package/src/react/index.tsx +184 -0
  98. package/src/test.ts +18 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,333 @@
1
+ # Convex Static Hosting
2
+
3
+ [![npm version](https://badge.fury.io/js/@convex-dev%2Fstatic-hosting.svg)](https://badge.fury.io/js/@convex-dev/static-hosting)
4
+
5
+ A Convex component that enables hosting static React/Vite apps using Convex
6
+ HTTP actions and file storage. No external hosting provider required!
7
+
8
+ ## Quick Start
9
+
10
+ ### Automated Setup (Recommended)
11
+
12
+ ```bash
13
+ npm install @convex-dev/static-hosting
14
+ npx @convex-dev/static-hosting setup
15
+ ```
16
+
17
+ The interactive wizard will:
18
+ 1. Create necessary Convex files
19
+ 2. Add deploy script to package.json
20
+
21
+ Then deploy:
22
+ ```bash
23
+ npm run deploy
24
+ ```
25
+
26
+ ### For LLMs / AI Assistants
27
+
28
+ If you're an LLM helping a user integrate this component, read [INTEGRATION.md](./INTEGRATION.md) for complete integration instructions optimized for AI consumption.
29
+
30
+ ### Manual Setup
31
+
32
+ See [Manual Setup](#manual-setup-1) section below for step-by-step instructions.
33
+
34
+ ## Features
35
+
36
+ - 🚀 **Simple deployment** - Upload your built files directly to Convex storage
37
+ - 🔒 **Secure by default** - Upload API uses internal functions (not publicly
38
+ accessible)
39
+ - 🔄 **SPA support** - Automatic fallback to index.html for client-side routing
40
+ - ⚡ **Smart caching** - Hashed assets get long-term caching, HTML is always
41
+ fresh with ETag support
42
+ - 🧹 **Auto cleanup** - Old deployment files are automatically garbage collected
43
+ - 📦 **Zero config** - Works out of the box with Vite, Create React App, and
44
+ other bundlers
45
+
46
+
47
+
48
+ https://github.com/user-attachments/assets/5eaf781f-87da-4292-9f96-38070c86cd39
49
+
50
+
51
+
52
+
53
+ ## Manual Setup
54
+
55
+ ### 1. Install
56
+
57
+ ```bash
58
+ npm install @convex-dev/static-hosting
59
+ ```
60
+
61
+ ### 2. Add to your `convex/convex.config.ts`:
62
+
63
+ ```ts
64
+ import { defineApp } from "convex/server";
65
+ import staticHosting from "@convex-dev/static-hosting/convex.config.js";
66
+
67
+ const app = defineApp();
68
+ app.use(staticHosting);
69
+
70
+ export default app;
71
+ ```
72
+
73
+ ### 3. Register HTTP routes
74
+
75
+ Create or update `convex/http.ts` to serve static files:
76
+
77
+ ```ts
78
+ import { httpRouter } from "convex/server";
79
+ import { registerStaticRoutes } from "@convex-dev/static-hosting";
80
+ import { components } from "./_generated/api";
81
+
82
+ const http = httpRouter();
83
+
84
+ // Serve static files at the root path with SPA fallback
85
+ registerStaticRoutes(http, components.staticHosting);
86
+
87
+ export default http;
88
+ ```
89
+
90
+ ### 4. Expose upload API (internal functions)
91
+
92
+ Create a file like `convex/staticHosting.ts`:
93
+
94
+ ```ts
95
+ import { exposeUploadApi } from "@convex-dev/static-hosting";
96
+ import { components } from "./_generated/api";
97
+
98
+ // These are INTERNAL functions - only callable via `npx convex run`
99
+ // NOT accessible from the public internet
100
+ export const { generateUploadUrl, recordAsset, gcOldAssets, listAssets } =
101
+ exposeUploadApi(components.staticHosting);
102
+ ```
103
+
104
+ **Note:** Run `npx convex dev` at least once after setup to push your schema and
105
+ enable HTTP actions. If you see the error "This Convex deployment does not have
106
+ HTTP actions enabled", it means the Convex backend hasn't been deployed yet.
107
+
108
+ ### 5. Add deploy script to package.json
109
+
110
+ ```json
111
+ {
112
+ "scripts": {
113
+ "build": "vite build",
114
+ "deploy:static": "npx @convex-dev/static-hosting upload --build --prod"
115
+ }
116
+ }
117
+ ```
118
+
119
+ **Important:** Use `--build` to ensure `VITE_CONVEX_URL` is set correctly for
120
+ production. Don't run `npm run build` separately before the upload command, as
121
+ that would use the dev URL from `.env.local`.
122
+
123
+ **CLI Options:**
124
+
125
+ ```bash
126
+ npx @convex-dev/static-hosting upload [options]
127
+
128
+ Options:
129
+ -d, --dist <path> Path to dist directory (default: ./dist)
130
+ -c, --component <name> Convex component name (default: staticHosting)
131
+ --prod Deploy to production Convex deployment
132
+ --dev Deploy to dev deployment (default)
133
+ -b, --build Run 'npm run build' with correct VITE_CONVEX_URL
134
+ -h, --help Show help
135
+ ```
136
+
137
+ **Examples:**
138
+
139
+ ```bash
140
+ # Deploy to production with automatic build
141
+ npx @convex-dev/static-hosting upload --build --prod
142
+
143
+ # Deploy to dev (for testing)
144
+ npx @convex-dev/static-hosting upload --build
145
+ ```
146
+
147
+ ### Using Non-Vite Bundlers
148
+
149
+ The CLI's `--build` flag sets `VITE_CONVEX_URL` when running your build command.
150
+ For bundlers that use different environment variable conventions, wrap your build
151
+ script to pass through the value:
152
+
153
+ **For Expo:**
154
+
155
+ ```json
156
+ {
157
+ "scripts": {
158
+ "build": "EXPO_PUBLIC_CONVEX_URL=${VITE_CONVEX_URL:-$EXPO_PUBLIC_CONVEX_URL} npx expo export --platform web"
159
+ }
160
+ }
161
+ ```
162
+
163
+ **For Next.js:**
164
+
165
+ ```json
166
+ {
167
+ "scripts": {
168
+ "build": "NEXT_PUBLIC_CONVEX_URL=${VITE_CONVEX_URL:-$NEXT_PUBLIC_CONVEX_URL} next build"
169
+ }
170
+ }
171
+ ```
172
+
173
+ The pattern `${VITE_CONVEX_URL:-$VAR}` uses `VITE_CONVEX_URL` if set (by the CLI),
174
+ otherwise falls back to your bundler-specific variable. This allows the CLI's
175
+ `--build` flag to work correctly while keeping your standalone `npm run build`
176
+ functional.
177
+
178
+ ## Deployment
179
+
180
+ ### One-Shot Deployment (Recommended)
181
+
182
+ Deploy both Convex backend and static files with a single command:
183
+
184
+ ```bash
185
+ # Make sure you're logged in
186
+ npx convex login
187
+
188
+ # Deploy everything
189
+ npx @convex-dev/static-hosting deploy
190
+ ```
191
+
192
+ The `deploy` command:
193
+ 1. Builds frontend with production `VITE_CONVEX_URL`
194
+ 2. Deploys Convex backend (`npx convex deploy`)
195
+ 3. Deploys static files to Convex storage
196
+
197
+ This minimizes the inconsistency window between backend and frontend updates.
198
+
199
+ **Deploy command options:**
200
+
201
+ ```bash
202
+ npx @convex-dev/static-hosting deploy [options]
203
+
204
+ Options:
205
+ -d, --dist <path> Path to dist directory (default: ./dist)
206
+ -c, --component <name> Convex component name (default: staticHosting)
207
+ --skip-build Skip the build step (use existing dist)
208
+ --skip-convex Skip Convex backend deployment
209
+ -h, --help Show help
210
+ ```
211
+
212
+ Add to `package.json` for easy deployments:
213
+
214
+ ```json
215
+ {
216
+ "scripts": {
217
+ "deploy": "npx @convex-dev/static-hosting deploy"
218
+ }
219
+ }
220
+ ```
221
+
222
+ ### Manual Two-Step Deployment
223
+
224
+ If you prefer more control, deploy separately:
225
+
226
+ ```bash
227
+ # Deploy Convex backend
228
+ npx convex deploy
229
+
230
+ # Deploy static files
231
+ npx @convex-dev/static-hosting upload --build --prod
232
+ ```
233
+
234
+ Your app is now live at `https://your-deployment.convex.site`
235
+
236
+ ## Security
237
+
238
+ The upload API uses **internal functions** that can only be called via:
239
+
240
+ - `npx convex run` (requires Convex CLI authentication)
241
+ - Other Convex functions (server-side only)
242
+
243
+ This means unauthorized users **cannot** upload files to your site, even if they
244
+ know your Convex URL.
245
+
246
+ ## Live Reload on Deploy
247
+
248
+ Connected clients can be notified when a new deployment is available:
249
+
250
+ 1. **Expose the deployment query**:
251
+
252
+ ```ts
253
+ import { exposeDeploymentQuery } from "@convex-dev/static-hosting";
254
+ import { components } from "./_generated/api";
255
+
256
+ export const { getCurrentDeployment } = exposeDeploymentQuery(
257
+ components.staticHosting,
258
+ );
259
+ ```
260
+
261
+ 2. **Add the update banner to your app**:
262
+
263
+ ```tsx
264
+ import { UpdateBanner } from "@convex-dev/static-hosting/react";
265
+ import { api } from "../convex/_generated/api";
266
+
267
+ function App() {
268
+ return (
269
+ <div>
270
+ <UpdateBanner
271
+ getCurrentDeployment={api.staticHosting.getCurrentDeployment}
272
+ message="New version available!"
273
+ buttonText="Refresh"
274
+ />
275
+ {/* rest of your app */}
276
+ </div>
277
+ );
278
+ }
279
+ ```
280
+
281
+ Or use the hook for custom UI:
282
+
283
+ ```tsx
284
+ import { useDeploymentUpdates } from "@convex-dev/static-hosting/react";
285
+
286
+ const { updateAvailable, reload, dismiss } = useDeploymentUpdates(
287
+ api.staticHosting.getCurrentDeployment,
288
+ );
289
+ ```
290
+
291
+ ## Configuration Options
292
+
293
+ ### `registerStaticRoutes`
294
+
295
+ ```ts
296
+ registerStaticRoutes(http, components.staticHosting, {
297
+ // URL prefix for static files (default: "/")
298
+ pathPrefix: "/app",
299
+
300
+ // Enable SPA fallback to index.html (default: true)
301
+ spaFallback: true,
302
+ });
303
+ ```
304
+
305
+ ## How It Works
306
+
307
+ 1. **Build Phase**: Your bundler (Vite, etc.) creates optimized files in `dist/`
308
+ 2. **Upload Phase**: The upload script uses `npx convex run` to:
309
+ - Generate signed upload URLs
310
+ - Upload each file to Convex storage
311
+ - Record file metadata in the component's database
312
+ - Garbage collect files from previous deployments
313
+ 3. **Serve Phase**: HTTP actions serve files from storage with:
314
+ - Correct Content-Type headers
315
+ - Smart cache control (immutable for hashed assets)
316
+ - SPA fallback for client-side routing
317
+
318
+ ## Example
319
+
320
+ Check out the [example](./example) directory for a complete working example.
321
+
322
+ ```bash
323
+ npm install
324
+ npm run dev
325
+ ```
326
+
327
+ ## Contributing
328
+
329
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup and guidelines.
330
+
331
+ ## License
332
+
333
+ Apache-2.0
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * One-shot deployment command that deploys both Convex backend and static files.
4
+ *
5
+ * Usage:
6
+ * npx @convex-dev/static-hosting deploy [options]
7
+ *
8
+ * This command:
9
+ * 1. Builds the frontend with the correct VITE_CONVEX_URL
10
+ * 2. Deploys the Convex backend (npx convex deploy)
11
+ * 3. Deploys static files to Convex storage
12
+ *
13
+ * The goal is to minimize the inconsistency window between backend and frontend.
14
+ */
15
+ export {};
16
+ //# sourceMappingURL=deploy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/cli/deploy.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;GAYG"}