@samebase/convex-hosting 0.0.0-stage → 0.3.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 (116) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/INTEGRATION.md +399 -0
  3. package/LICENSE +201 -0
  4. package/NOTICE +7 -0
  5. package/README.md +470 -2
  6. package/dist/cli/args.d.ts +28 -0
  7. package/dist/cli/args.d.ts.map +1 -0
  8. package/dist/cli/args.js +148 -0
  9. package/dist/cli/args.js.map +1 -0
  10. package/dist/cli/argumentChunks.d.ts +3 -0
  11. package/dist/cli/argumentChunks.d.ts.map +1 -0
  12. package/dist/cli/argumentChunks.js +29 -0
  13. package/dist/cli/argumentChunks.js.map +1 -0
  14. package/dist/cli/commands.d.ts +8 -0
  15. package/dist/cli/commands.d.ts.map +1 -0
  16. package/dist/cli/commands.js +56 -0
  17. package/dist/cli/commands.js.map +1 -0
  18. package/dist/cli/componentName.d.ts +32 -0
  19. package/dist/cli/componentName.d.ts.map +1 -0
  20. package/dist/cli/componentName.js +43 -0
  21. package/dist/cli/componentName.js.map +1 -0
  22. package/dist/cli/deploy.d.ts +16 -0
  23. package/dist/cli/deploy.d.ts.map +1 -0
  24. package/dist/cli/deploy.js +283 -0
  25. package/dist/cli/deploy.js.map +1 -0
  26. package/dist/cli/deployEnvironment.d.ts +10 -0
  27. package/dist/cli/deployEnvironment.d.ts.map +1 -0
  28. package/dist/cli/deployEnvironment.js +12 -0
  29. package/dist/cli/deployEnvironment.js.map +1 -0
  30. package/dist/cli/index.d.ts +12 -0
  31. package/dist/cli/index.d.ts.map +1 -0
  32. package/dist/cli/index.js +60 -0
  33. package/dist/cli/index.js.map +1 -0
  34. package/dist/cli/upload.d.ts +22 -0
  35. package/dist/cli/upload.d.ts.map +1 -0
  36. package/dist/cli/upload.js +668 -0
  37. package/dist/cli/upload.js.map +1 -0
  38. package/dist/client/_generated/_ignore.d.ts +1 -0
  39. package/dist/client/_generated/_ignore.d.ts.map +1 -0
  40. package/dist/client/_generated/_ignore.js +3 -0
  41. package/dist/client/_generated/_ignore.js.map +1 -0
  42. package/dist/client/index.d.ts +119 -0
  43. package/dist/client/index.d.ts.map +1 -0
  44. package/dist/client/index.js +272 -0
  45. package/dist/client/index.js.map +1 -0
  46. package/dist/component/_generated/api.d.ts +38 -0
  47. package/dist/component/_generated/api.d.ts.map +1 -0
  48. package/dist/component/_generated/api.js +31 -0
  49. package/dist/component/_generated/api.js.map +1 -0
  50. package/dist/component/_generated/component.d.ts +43 -0
  51. package/dist/component/_generated/component.d.ts.map +1 -0
  52. package/dist/component/_generated/component.js +11 -0
  53. package/dist/component/_generated/component.js.map +1 -0
  54. package/dist/component/_generated/dataModel.d.ts +46 -0
  55. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  56. package/dist/component/_generated/dataModel.js +11 -0
  57. package/dist/component/_generated/dataModel.js.map +1 -0
  58. package/dist/component/_generated/server.d.ts +121 -0
  59. package/dist/component/_generated/server.d.ts.map +1 -0
  60. package/dist/component/_generated/server.js +78 -0
  61. package/dist/component/_generated/server.js.map +1 -0
  62. package/dist/component/convex.config.d.ts +3 -0
  63. package/dist/component/convex.config.d.ts.map +1 -0
  64. package/dist/component/convex.config.js +3 -0
  65. package/dist/component/convex.config.js.map +1 -0
  66. package/dist/component/http.d.ts +4 -0
  67. package/dist/component/http.d.ts.map +1 -0
  68. package/dist/component/http.js +125 -0
  69. package/dist/component/http.js.map +1 -0
  70. package/dist/component/lib.d.ts +164 -0
  71. package/dist/component/lib.d.ts.map +1 -0
  72. package/dist/component/lib.js +768 -0
  73. package/dist/component/lib.js.map +1 -0
  74. package/dist/component/schema.d.ts +84 -0
  75. package/dist/component/schema.d.ts.map +1 -0
  76. package/dist/component/schema.js +69 -0
  77. package/dist/component/schema.js.map +1 -0
  78. package/dist/component/serving.d.ts +17 -0
  79. package/dist/component/serving.d.ts.map +1 -0
  80. package/dist/component/serving.js +150 -0
  81. package/dist/component/serving.js.map +1 -0
  82. package/dist/react/index.d.ts +59 -0
  83. package/dist/react/index.d.ts.map +1 -0
  84. package/dist/react/index.js +137 -0
  85. package/dist/react/index.js.map +1 -0
  86. package/package.json +78 -3
  87. package/src/cli/args.test.ts +79 -0
  88. package/src/cli/args.ts +153 -0
  89. package/src/cli/argumentChunks.test.ts +27 -0
  90. package/src/cli/argumentChunks.ts +40 -0
  91. package/src/cli/commands.ts +68 -0
  92. package/src/cli/componentName.test.ts +41 -0
  93. package/src/cli/componentName.ts +46 -0
  94. package/src/cli/deploy.ts +336 -0
  95. package/src/cli/deployEnvironment.test.ts +27 -0
  96. package/src/cli/deployEnvironment.ts +17 -0
  97. package/src/cli/index.ts +65 -0
  98. package/src/cli/upload.ts +885 -0
  99. package/src/client/_generated/_ignore.ts +1 -0
  100. package/src/client/index.test.ts +510 -0
  101. package/src/client/index.ts +355 -0
  102. package/src/client/setup.test.ts +22 -0
  103. package/src/component/_generated/api.ts +54 -0
  104. package/src/component/_generated/component.ts +55 -0
  105. package/src/component/_generated/dataModel.ts +60 -0
  106. package/src/component/_generated/server.ts +156 -0
  107. package/src/component/convex.config.ts +3 -0
  108. package/src/component/http.test.ts +223 -0
  109. package/src/component/http.ts +144 -0
  110. package/src/component/lib.test.ts +1007 -0
  111. package/src/component/lib.ts +862 -0
  112. package/src/component/schema.ts +75 -0
  113. package/src/component/serving.ts +158 -0
  114. package/src/component/setup.test.ts +11 -0
  115. package/src/react/index.tsx +197 -0
  116. package/src/test.ts +23 -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/NOTICE ADDED
@@ -0,0 +1,7 @@
1
+ @samebase/convex-hosting
2
+ Copyright 2026 Nicușor Chiciuc
3
+
4
+ This package is a modified version of static-hosting
5
+ (https://github.com/get-convex/static-hosting), developed by Convex and licensed under the Apache
6
+ License, Version 2.0. Samebase changed the files in this package; the git history of
7
+ https://github.com/samebase/convex-hosting records each change.
package/README.md CHANGED
@@ -1,3 +1,471 @@
1
- # Temporary Holding Version
1
+ # Convex Hosting
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://badge.fury.io/js/@samebase%2Fconvex-hosting.svg)](https://badge.fury.io/js/@samebase/convex-hosting)
4
+
5
+ A Convex component for hosting static React/Vite apps directly on Convex: no separate hosting
6
+ provider, no DNS to wire up, no second deploy target. Run one command and your frontend is live at
7
+ `https://<deployment>.convex.site` alongside your backend. For server-rendered TanStack Start pages,
8
+ add
9
+ [`@samebase/convex-hosting-tanstack-start`](https://github.com/samebase/convex-hosting/tree/main/packages/convex-hosting-tanstack-start).
10
+
11
+ This is Samebase's fork of [get-convex/static-hosting](https://github.com/get-convex/static-hosting)
12
+ (Apache-2.0). It is not affiliated with or endorsed by Convex.
13
+
14
+ ## Features
15
+
16
+ - 🚀 **One-command deploy:** build, push backend, and upload static files in a single step.
17
+ - 🔄 **SPA routing:** paths without an extension fall back to `index.html`.
18
+ - ⚡ **Smart caching:** static files are cached for speed, with safe updates when a new version is
19
+ deployed.
20
+ - 🔔 **Deployment update notifications:** show connected users a prompt when a new version is ready.
21
+ - 🔒 **Authenticated uploads:** uploads go through the Convex CLI's authenticated session; there's
22
+ no public upload endpoint.
23
+ - 🧹 **Automatic cleanup:** replaced non-HTML files stay available for at least seven days, so open
24
+ pages keep working, and a later deploy removes them.
25
+
26
+ ## Quick Start
27
+
28
+ > **Coming from `@convex-dev/static-hosting`?** See
29
+ > [Switching from @convex-dev/static-hosting](#switching-from-convex-devstatic-hosting).
30
+
31
+ Follow the three [setup steps](#setup), then run:
32
+
33
+ ```bash
34
+ npm run deploy
35
+ ```
36
+
37
+ Your app is live at `https://<deployment>.convex.site`.
38
+
39
+ ## Setup
40
+
41
+ ### 1. Install
42
+
43
+ ```bash
44
+ npm install @samebase/convex-hosting
45
+ ```
46
+
47
+ ### 2. Register the component
48
+
49
+ `convex/convex.config.ts`:
50
+
51
+ ```ts
52
+ import { defineApp } from "convex/server";
53
+ import hosting from "@samebase/convex-hosting/convex.config";
54
+
55
+ // Your own HTTP endpoints (convex/http.ts) are served under /api so the
56
+ // static site can own the root.
57
+ const app = defineApp({ httpPrefix: "/api" });
58
+ app.use(hosting, { httpPrefix: "/" });
59
+
60
+ export default app;
61
+ ```
62
+
63
+ This is the fastest serving mode. The component owns `/`, while your app's `convex/http.ts` routes
64
+ move under `/api/...`.
65
+
66
+ If existing callbacks or auth routes must stay at the root, use
67
+ [app-owned root routing](#keep-existing-http-routes-at-the-root). To host the site under a sub-path,
68
+ see [Mounting under a sub-path](#mounting-under-a-sub-path).
69
+
70
+ ### 3. Add a deploy script
71
+
72
+ ```json
73
+ {
74
+ "scripts": {
75
+ "deploy": "npx @samebase/convex-hosting deploy"
76
+ }
77
+ }
78
+ ```
79
+
80
+ That's it.
81
+
82
+ ### Keep existing HTTP routes at the root
83
+
84
+ Do not move stable webhook, auth, or API URLs just to add hosting. Leave the component's HTTP routes
85
+ unmounted and register the static catch-all in your existing router.
86
+
87
+ `convex/convex.config.ts`:
88
+
89
+ ```ts
90
+ import { defineApp } from "convex/server";
91
+ import hosting from "@samebase/convex-hosting/convex.config";
92
+
93
+ const app = defineApp();
94
+ app.use(hosting); // no httpPrefix
95
+
96
+ export default app;
97
+ ```
98
+
99
+ `convex/http.ts`:
100
+
101
+ ```ts
102
+ import { httpRouter } from "convex/server";
103
+ import { registerStaticRoutes } from "@samebase/convex-hosting";
104
+ import { components } from "./_generated/api";
105
+
106
+ const http = httpRouter();
107
+
108
+ // Register exact app routes first. Existing auth/webhook helpers can stay here.
109
+ // auth.addHttpRoutes(http);
110
+ registerStaticRoutes(http, components.hosting);
111
+
112
+ export default http;
113
+ ```
114
+
115
+ Exact routes win over the static catch-all, so existing URLs keep working. The component still owns
116
+ uploads, deployment state, and file storage. This mode adds an internal query and storage fetch on
117
+ an uncached request, so prefer the component-owned mode when you do not need root-level app routes.
118
+
119
+ ### Using non-Vite bundlers
120
+
121
+ The `deploy` build step and `upload --build` set `VITE_CONVEX_URL`. For bundlers that use different
122
+ environment variable conventions, wrap your build script to pass through the value:
123
+
124
+ **For Expo:**
125
+
126
+ ```json
127
+ {
128
+ "scripts": {
129
+ "build": "EXPO_PUBLIC_CONVEX_URL=${VITE_CONVEX_URL:-$EXPO_PUBLIC_CONVEX_URL} npx expo export --platform web"
130
+ }
131
+ }
132
+ ```
133
+
134
+ **For Next.js:**
135
+
136
+ ```json
137
+ {
138
+ "scripts": {
139
+ "build": "NEXT_PUBLIC_CONVEX_URL=${VITE_CONVEX_URL:-$NEXT_PUBLIC_CONVEX_URL} next build"
140
+ }
141
+ }
142
+ ```
143
+
144
+ The pattern `${VITE_CONVEX_URL:-$VAR}` uses `VITE_CONVEX_URL` if set by the CLI and otherwise falls
145
+ back to your bundler-specific variable. This keeps both the CLI-driven build and standalone
146
+ `npm run build` working.
147
+
148
+ ## Deployment
149
+
150
+ Deploy both Convex backend and static files with a single command:
151
+
152
+ ```bash
153
+ npx convex login # first time only
154
+ npx @samebase/convex-hosting deploy
155
+ ```
156
+
157
+ The `deploy` command:
158
+
159
+ 1. Builds your frontend with the production `VITE_CONVEX_URL`.
160
+ 2. Deploys the Convex backend.
161
+ 3. Uploads `dist/` to Convex.
162
+
163
+ For more control, you can run the two halves separately:
164
+
165
+ ```bash
166
+ npx convex deploy
167
+ npx @samebase/convex-hosting upload --build --prod
168
+ ```
169
+
170
+ Your app is live at `https://<deployment>.convex.site`.
171
+
172
+ ## Development workflow
173
+
174
+ Use your normal frontend dev server during development:
175
+
176
+ ```bash
177
+ # Terminal 1
178
+ npx convex dev
179
+
180
+ # Terminal 2
181
+ npm run dev
182
+ ```
183
+
184
+ For Vite, that keeps HMR and fast local feedback. The hosting component is the deploy target, not a
185
+ replacement dev server. Uploading every edit to a development deployment is slower and loses HMR,
186
+ even when an agent writes most of the code. Humans still need the quick loop for visual checks,
187
+ transient UI state, and debugging.
188
+
189
+ Before release, run one hosted smoke test against the development deployment:
190
+
191
+ ```bash
192
+ npx @samebase/convex-hosting upload --build
193
+ ```
194
+
195
+ Then use `deploy` for production. This split keeps the dev loop fast while still testing the real
196
+ HTTP, caching, base-path, and SPA behavior before shipping.
197
+
198
+ ## CLI options
199
+
200
+ ```bash
201
+ npx @samebase/convex-hosting deploy [options]
202
+ -d, --dist <path> Path to dist directory (default: ./dist)
203
+ -c, --component <name> Component instance name (default: hosting)
204
+ --skip-build Skip the build step (use existing dist)
205
+ --skip-convex Skip Convex backend deployment
206
+ --build-command <cmd> Build command to run (default: 'npm run build')
207
+ --no-spa Disable SPA fallback (404 instead of /index.html)
208
+ --spa Enable SPA fallback (default)
209
+ --cdn Use the legacy convex-fs integration
210
+ --cdn-delete-function Legacy app function that deletes CDN blobs
211
+
212
+ npx @samebase/convex-hosting upload [options]
213
+ -d, --dist <path> Path to dist directory (default: ./dist)
214
+ -c, --component <name> Component instance name (default: hosting)
215
+ --prod Deploy to production deployment
216
+ --preview-name <name> Upload to the named preview deployment
217
+ -b, --build Run 'npm run build' with VITE_CONVEX_URL set
218
+ --build-command <cmd> Override the build command; implies --build
219
+ --no-spa Disable SPA fallback (404 instead of /index.html)
220
+ --spa Enable SPA fallback (default)
221
+ --cdn Use the legacy convex-fs integration
222
+ --cdn-delete-function Legacy app function that deletes CDN blobs
223
+ -j, --concurrency <n> Parallel upload workers (default: 5)
224
+ ```
225
+
226
+ `--preview-name` selects the deployment the same way as `npx convex run --preview-name`, so a dev or
227
+ production `CONVEX_DEPLOY_KEY` takes precedence over it.
228
+
229
+ Each upload is published atomically, so visitors never see a page that refers to assets that are not
230
+ available yet. Failed uploads leave the previous deployment live. Replaced non-HTML files stay
231
+ available for at least seven days, so pages that are already open can still load their scripts. A
232
+ later upload removes expired files. See [INTEGRATION.md](./INTEGRATION.md) for upload limits and
233
+ lifecycle details.
234
+
235
+ Convex HTTP routes currently support GET but not HEAD. Configure uptime checks to make a lightweight
236
+ GET request rather than a HEAD request.
237
+
238
+ If you mount the component under a different name with `app.use(hosting, { name: "custom" })`, pass
239
+ `--component custom` and replace every generated `components.hosting` reference with
240
+ `components.custom`.
241
+
242
+ Do not use `--cdn` for a new integration. It targets an older ConvexFS HTTP API and is retained only
243
+ for existing deployments. Legacy CDN users must keep app-owned root routing because `/fs/upload` and
244
+ `/fs/blobs/*` are root app routes. See `INTEGRATION.md` for the current limitation.
245
+
246
+ ## Security
247
+
248
+ The upload API uses **internal functions** in the Component that can only be called via:
249
+
250
+ - `npx convex run` (requires Convex CLI authentication)
251
+ - Other Convex functions in the Component (server-side only)
252
+
253
+ This means unauthorized users **cannot** upload files to your site, even if they know your Convex
254
+ URL.
255
+
256
+ ## Reload prompt after deploy (optional)
257
+
258
+ If you want a banner that prompts users to reload when a new deployment ships, expose the deployment
259
+ query in your app and drop in `<UpdateBanner />`:
260
+
261
+ `convex/hosting.ts`:
262
+
263
+ ```ts
264
+ import { exposeDeploymentQuery } from "@samebase/convex-hosting";
265
+ import { components } from "./_generated/api";
266
+
267
+ export const { getCurrentDeployment } = exposeDeploymentQuery(components.hosting);
268
+ ```
269
+
270
+ `src/App.tsx`:
271
+
272
+ ```tsx
273
+ import { UpdateBanner } from "@samebase/convex-hosting/react";
274
+
275
+ function App() {
276
+ return (
277
+ <>
278
+ <UpdateBanner message="New version!" buttonText="Reload" />
279
+ {/* ... */}
280
+ </>
281
+ );
282
+ }
283
+ ```
284
+
285
+ `UpdateBanner` resolves `api.hosting.getCurrentDeployment` automatically. If you re-export the query
286
+ under a different module name, pass it explicitly:
287
+
288
+ ```tsx
289
+ import { api } from "../convex/_generated/api";
290
+ <UpdateBanner getCurrentDeployment={api.myModule.getCurrentDeployment} />;
291
+ ```
292
+
293
+ For custom UI, use the hook:
294
+
295
+ ```tsx
296
+ import { useDeploymentUpdates } from "@samebase/convex-hosting/react";
297
+
298
+ const { updateAvailable, reload, dismiss } = useDeploymentUpdates();
299
+ ```
300
+
301
+ ## Mounting under a sub-path
302
+
303
+ Mount the static site under a sub-path if you have other routes at the root:
304
+
305
+ ```ts
306
+ app.use(hosting, { httpPrefix: "/app/" });
307
+ ```
308
+
309
+ You'll also need to tell your bundler about the base path so the emitted HTML references the right
310
+ URLs. The CLI sets a `CONVEX_HOSTING_BASE_PATH` env var matching the component's mount when it runs
311
+ your build, so `vite.config.ts` can read it directly:
312
+
313
+ ```ts
314
+ import { defineConfig } from "vite";
315
+
316
+ export default defineConfig({
317
+ base: process.env.CONVEX_HOSTING_BASE_PATH ?? "/",
318
+ });
319
+ ```
320
+
321
+ Root-mounted apps don't need this; the default is `/`. For webpack use `publicPath`, for Next.js
322
+ `assetPrefix`.
323
+
324
+ ## SPA routing
325
+
326
+ By default, requests for a path with no file extension that doesn't match an uploaded file fall back
327
+ to `index.html`, so client-side routes like `/dashboard/settings` work on reload. For a multi-page
328
+ app where unknown paths should be a real 404, deploy with `--no-spa`:
329
+
330
+ ```bash
331
+ npx @samebase/convex-hosting deploy --no-spa
332
+ ```
333
+
334
+ The setting is stored with the deployment, so it travels with the code you ship rather than living
335
+ in a separate env var. Requests for paths with an extension (e.g. `/missing.js`) always 404 when not
336
+ found, regardless of this setting.
337
+
338
+ ## Custom routing (SSR, prerendered pages)
339
+
340
+ `registerStaticRoutes` decides what every unmatched path returns. When your app needs to decide
341
+ instead, for example to server-render pages, serve prerendered pages next to an SPA shell, or
342
+ redirect to canonical URLs, write the catch-all route yourself and call `serveStaticAsset` for
343
+ uploaded files. Install the component without `httpPrefix`, as in
344
+ [Keep existing HTTP routes at the root](#keep-existing-http-routes-at-the-root).
345
+
346
+ ```ts
347
+ import { httpRouter } from "convex/server";
348
+ import { decodeRequestPath, serveStaticAsset } from "@samebase/convex-hosting";
349
+ import { components } from "./_generated/api";
350
+ import { httpAction } from "./_generated/server";
351
+
352
+ const http = httpRouter();
353
+
354
+ http.route({
355
+ pathPrefix: "/",
356
+ method: "GET",
357
+ handler: httpAction(async (ctx, request) => {
358
+ const file = await serveStaticAsset(ctx, components.hosting, request);
359
+ if (file) return file;
360
+
361
+ // A missing bundle file is a 404, not a page.
362
+ const path = decodeRequestPath(new URL(request.url).pathname);
363
+ if (path === null || path.startsWith("/assets/")) {
364
+ return new Response("Not Found", {
365
+ status: 404,
366
+ headers: { "Cache-Control": "no-store" },
367
+ });
368
+ }
369
+ return await renderPage(request);
370
+ }),
371
+ });
372
+
373
+ export default http;
374
+ ```
375
+
376
+ `serveStaticAsset` returns the file with the same headers as `registerStaticRoutes`, or `null` when
377
+ no file matches, including a request path with malformed percent-encoding. It never returns the
378
+ setup page or a 404, so your code decides what happens next. Only a found file whose storage can't
379
+ be read gets an error response (500). The lookup is exact: `/` is not mapped to `/index.html`, and
380
+ SPA fallback is off unless you pass `spaFallback: true`.
381
+
382
+ Pass `path` to serve a different file, such as a prerendered page or the SPA shell. It is the
383
+ decoded path of the uploaded file, starting with `/`. If your route has a prefix, remove it from
384
+ `path`:
385
+
386
+ ```ts
387
+ const page = await serveStaticAsset(ctx, components.hosting, request, {
388
+ path: "/about/index.html",
389
+ });
390
+ const shell = await serveStaticAsset(ctx, components.hosting, request, {
391
+ path: "/index.html",
392
+ });
393
+ ```
394
+
395
+ When the backend renders your pages, pushing the backend and uploading files are separate steps, so
396
+ right after a deploy a page can briefly refer to scripts that are not uploaded yet. That is why the
397
+ missing-asset response above uses `Cache-Control: no-store`: a CDN would otherwise keep serving
398
+ the 404.
399
+
400
+ Use `decodeRequestPath` for your own path checks, so an encoded request such as `/%61ssets/app.js`
401
+ still matches `/assets/`.
402
+
403
+ See
404
+ [`examples/tanstack-ssr/`](https://github.com/samebase/convex-hosting/tree/main/examples/tanstack-ssr)
405
+ for TanStack Start pages rendered in a Convex HTTP action this way.
406
+
407
+ ## Switching from @convex-dev/static-hosting
408
+
409
+ This package continues `@convex-dev/static-hosting` 0.2. To switch an app:
410
+
411
+ 1. Replace the dependency with `@samebase/convex-hosting`, and change every import from
412
+ `@convex-dev/static-hosting` to `@samebase/convex-hosting`, including `/convex.config` and
413
+ `/react`.
414
+ 2. Keep the existing component instance, so the uploaded files and the site URLs stay:
415
+
416
+ ```ts
417
+ import hosting from "@samebase/convex-hosting/convex.config";
418
+
419
+ app.use(hosting, { name: "staticHosting", httpPrefix: "/" });
420
+ ```
421
+
422
+ Keep the `httpPrefix` the app used before. The code keeps using `components.staticHosting`, and
423
+ the CLI finds this instance without `--component`. It prints a note that the default name is now
424
+ `hosting`.
425
+
426
+ 3. Rename `convex/staticHosting.ts` to `convex/hosting.ts`. `<UpdateBanner />` and
427
+ `useDeploymentUpdates()` look up `api.hosting.getCurrentDeployment` by default. To keep the old
428
+ file, pass `api.staticHosting.getCurrentDeployment` to them instead.
429
+ 4. In package scripts, replace `@convex-dev/static-hosting` with `@samebase/convex-hosting` (for
430
+ example `npx @samebase/convex-hosting deploy`) and the bare `static-hosting` command with
431
+ `convex-hosting`. In the bundler config, replace `STATIC_HOSTING_BASE_PATH` with
432
+ `CONVEX_HOSTING_BASE_PATH`.
433
+ 5. Deploy as usual.
434
+
435
+ To use the new default name instead, remove `name: "staticHosting"`, replace
436
+ `components.staticHosting` with `components.hosting`, and deploy. The new instance starts empty, so
437
+ the deploy uploads the files again.
438
+
439
+ An app on `@convex-dev/static-hosting` 0.1.x first follows upstream's
440
+ [0.1.x to 0.2.x migration guide](https://github.com/get-convex/static-hosting/blob/main/MIGRATION.md),
441
+ because 0.2 moved the files into the component.
442
+
443
+ ## How it works
444
+
445
+ 1. **Build:** your bundler emits `dist/`.
446
+ 2. **Upload:** the CLI uses your authenticated Convex session to generate signed upload URLs, push
447
+ files to Convex storage, record metadata, and GC old deployments.
448
+ 3. **Serve:** an HTTP action looks up the requested path, streams the file with the right
449
+ `Content-Type`, applies long-term caching for hashed assets, and falls back to `index.html` for
450
+ SPA routes.
451
+
452
+ ## Example
453
+
454
+ See [`examples/spa/`](https://github.com/samebase/convex-hosting/tree/main/examples/spa) for a
455
+ complete Vite + React app, and
456
+ [`examples/tanstack-ssr/`](https://github.com/samebase/convex-hosting/tree/main/examples/tanstack-ssr)
457
+ for server rendering with TanStack Start.
458
+
459
+ ```bash
460
+ pnpm install
461
+ cd examples/spa
462
+ pnpm run dev
463
+ ```
464
+
465
+ ## Contributing
466
+
467
+ See [CONTRIBUTING.md](https://github.com/samebase/convex-hosting/blob/main/CONTRIBUTING.md).
468
+
469
+ ## License
470
+
471
+ Apache-2.0