@samebase/convex-hosting 0.0.0-stage → 0.3.1
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/CHANGELOG.md +133 -0
- package/INTEGRATION.md +399 -0
- package/LICENSE +201 -0
- package/NOTICE +7 -0
- package/README.md +471 -2
- package/dist/cli/args.d.ts +28 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +148 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/argumentChunks.d.ts +3 -0
- package/dist/cli/argumentChunks.d.ts.map +1 -0
- package/dist/cli/argumentChunks.js +29 -0
- package/dist/cli/argumentChunks.js.map +1 -0
- package/dist/cli/collectFiles.d.ts +10 -0
- package/dist/cli/collectFiles.d.ts.map +1 -0
- package/dist/cli/collectFiles.js +53 -0
- package/dist/cli/collectFiles.js.map +1 -0
- package/dist/cli/commands.d.ts +8 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +56 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/componentName.d.ts +32 -0
- package/dist/cli/componentName.d.ts.map +1 -0
- package/dist/cli/componentName.js +43 -0
- package/dist/cli/componentName.js.map +1 -0
- package/dist/cli/deploy.d.ts +16 -0
- package/dist/cli/deploy.d.ts.map +1 -0
- package/dist/cli/deploy.js +283 -0
- package/dist/cli/deploy.js.map +1 -0
- package/dist/cli/deployEnvironment.d.ts +10 -0
- package/dist/cli/deployEnvironment.d.ts.map +1 -0
- package/dist/cli/deployEnvironment.js +12 -0
- package/dist/cli/deployEnvironment.js.map +1 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +60 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/upload.d.ts +22 -0
- package/dist/cli/upload.d.ts.map +1 -0
- package/dist/cli/upload.js +630 -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 +119 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +272 -0
- package/dist/client/index.js.map +1 -0
- package/dist/component/_generated/api.d.ts +38 -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 +43 -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/http.d.ts +4 -0
- package/dist/component/http.d.ts.map +1 -0
- package/dist/component/http.js +125 -0
- package/dist/component/http.js.map +1 -0
- package/dist/component/lib.d.ts +164 -0
- package/dist/component/lib.d.ts.map +1 -0
- package/dist/component/lib.js +768 -0
- package/dist/component/lib.js.map +1 -0
- package/dist/component/schema.d.ts +84 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +69 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/serving.d.ts +17 -0
- package/dist/component/serving.d.ts.map +1 -0
- package/dist/component/serving.js +150 -0
- package/dist/component/serving.js.map +1 -0
- package/dist/react/index.d.ts +59 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +137 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +78 -3
- package/src/cli/args.test.ts +79 -0
- package/src/cli/args.ts +153 -0
- package/src/cli/argumentChunks.test.ts +27 -0
- package/src/cli/argumentChunks.ts +40 -0
- package/src/cli/collectFiles.test.ts +26 -0
- package/src/cli/collectFiles.ts +59 -0
- package/src/cli/commands.ts +68 -0
- package/src/cli/componentName.test.ts +41 -0
- package/src/cli/componentName.ts +46 -0
- package/src/cli/deploy.ts +336 -0
- package/src/cli/deployEnvironment.test.ts +27 -0
- package/src/cli/deployEnvironment.ts +17 -0
- package/src/cli/index.ts +65 -0
- package/src/cli/upload.ts +837 -0
- package/src/client/_generated/_ignore.ts +1 -0
- package/src/client/index.test.ts +510 -0
- package/src/client/index.ts +355 -0
- package/src/client/setup.test.ts +22 -0
- package/src/component/_generated/api.ts +54 -0
- package/src/component/_generated/component.ts +55 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/convex.config.ts +3 -0
- package/src/component/http.test.ts +223 -0
- package/src/component/http.ts +144 -0
- package/src/component/lib.test.ts +1007 -0
- package/src/component/lib.ts +862 -0
- package/src/component/schema.ts +75 -0
- package/src/component/serving.ts +158 -0
- package/src/component/setup.test.ts +11 -0
- package/src/react/index.tsx +197 -0
- 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,472 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Convex Hosting
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](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. It skips `_headers` and `_redirects` at the root of `dist/`:
|
|
162
|
+
Cloudflare and Netlify read these files as hosting rules, and this package does not apply them.
|
|
163
|
+
|
|
164
|
+
For more control, you can run the two halves separately:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
npx convex deploy
|
|
168
|
+
npx @samebase/convex-hosting upload --build --prod
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Your app is live at `https://<deployment>.convex.site`.
|
|
172
|
+
|
|
173
|
+
## Development workflow
|
|
174
|
+
|
|
175
|
+
Use your normal frontend dev server during development:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Terminal 1
|
|
179
|
+
npx convex dev
|
|
180
|
+
|
|
181
|
+
# Terminal 2
|
|
182
|
+
npm run dev
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
For Vite, that keeps HMR and fast local feedback. The hosting component is the deploy target, not a
|
|
186
|
+
replacement dev server. Uploading every edit to a development deployment is slower and loses HMR,
|
|
187
|
+
even when an agent writes most of the code. Humans still need the quick loop for visual checks,
|
|
188
|
+
transient UI state, and debugging.
|
|
189
|
+
|
|
190
|
+
Before release, run one hosted smoke test against the development deployment:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
npx @samebase/convex-hosting upload --build
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Then use `deploy` for production. This split keeps the dev loop fast while still testing the real
|
|
197
|
+
HTTP, caching, base-path, and SPA behavior before shipping.
|
|
198
|
+
|
|
199
|
+
## CLI options
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
npx @samebase/convex-hosting deploy [options]
|
|
203
|
+
-d, --dist <path> Path to dist directory (default: ./dist)
|
|
204
|
+
-c, --component <name> Component instance name (default: hosting)
|
|
205
|
+
--skip-build Skip the build step (use existing dist)
|
|
206
|
+
--skip-convex Skip Convex backend deployment
|
|
207
|
+
--build-command <cmd> Build command to run (default: 'npm run build')
|
|
208
|
+
--no-spa Disable SPA fallback (404 instead of /index.html)
|
|
209
|
+
--spa Enable SPA fallback (default)
|
|
210
|
+
--cdn Use the legacy convex-fs integration
|
|
211
|
+
--cdn-delete-function Legacy app function that deletes CDN blobs
|
|
212
|
+
|
|
213
|
+
npx @samebase/convex-hosting upload [options]
|
|
214
|
+
-d, --dist <path> Path to dist directory (default: ./dist)
|
|
215
|
+
-c, --component <name> Component instance name (default: hosting)
|
|
216
|
+
--prod Deploy to production deployment
|
|
217
|
+
--preview-name <name> Upload to the named preview deployment
|
|
218
|
+
-b, --build Run 'npm run build' with VITE_CONVEX_URL set
|
|
219
|
+
--build-command <cmd> Override the build command; implies --build
|
|
220
|
+
--no-spa Disable SPA fallback (404 instead of /index.html)
|
|
221
|
+
--spa Enable SPA fallback (default)
|
|
222
|
+
--cdn Use the legacy convex-fs integration
|
|
223
|
+
--cdn-delete-function Legacy app function that deletes CDN blobs
|
|
224
|
+
-j, --concurrency <n> Parallel upload workers (default: 5)
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
`--preview-name` selects the deployment the same way as `npx convex run --preview-name`, so a dev or
|
|
228
|
+
production `CONVEX_DEPLOY_KEY` takes precedence over it.
|
|
229
|
+
|
|
230
|
+
Each upload is published atomically, so visitors never see a page that refers to assets that are not
|
|
231
|
+
available yet. Failed uploads leave the previous deployment live. Replaced non-HTML files stay
|
|
232
|
+
available for at least seven days, so pages that are already open can still load their scripts. A
|
|
233
|
+
later upload removes expired files. See [INTEGRATION.md](./INTEGRATION.md) for upload limits and
|
|
234
|
+
lifecycle details.
|
|
235
|
+
|
|
236
|
+
Convex HTTP routes currently support GET but not HEAD. Configure uptime checks to make a lightweight
|
|
237
|
+
GET request rather than a HEAD request.
|
|
238
|
+
|
|
239
|
+
If you mount the component under a different name with `app.use(hosting, { name: "custom" })`, pass
|
|
240
|
+
`--component custom` and replace every generated `components.hosting` reference with
|
|
241
|
+
`components.custom`.
|
|
242
|
+
|
|
243
|
+
Do not use `--cdn` for a new integration. It targets an older ConvexFS HTTP API and is retained only
|
|
244
|
+
for existing deployments. Legacy CDN users must keep app-owned root routing because `/fs/upload` and
|
|
245
|
+
`/fs/blobs/*` are root app routes. See `INTEGRATION.md` for the current limitation.
|
|
246
|
+
|
|
247
|
+
## Security
|
|
248
|
+
|
|
249
|
+
The upload API uses **internal functions** in the Component that can only be called via:
|
|
250
|
+
|
|
251
|
+
- `npx convex run` (requires Convex CLI authentication)
|
|
252
|
+
- Other Convex functions in the Component (server-side only)
|
|
253
|
+
|
|
254
|
+
This means unauthorized users **cannot** upload files to your site, even if they know your Convex
|
|
255
|
+
URL.
|
|
256
|
+
|
|
257
|
+
## Reload prompt after deploy (optional)
|
|
258
|
+
|
|
259
|
+
If you want a banner that prompts users to reload when a new deployment ships, expose the deployment
|
|
260
|
+
query in your app and drop in `<UpdateBanner />`:
|
|
261
|
+
|
|
262
|
+
`convex/hosting.ts`:
|
|
263
|
+
|
|
264
|
+
```ts
|
|
265
|
+
import { exposeDeploymentQuery } from "@samebase/convex-hosting";
|
|
266
|
+
import { components } from "./_generated/api";
|
|
267
|
+
|
|
268
|
+
export const { getCurrentDeployment } = exposeDeploymentQuery(components.hosting);
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
`src/App.tsx`:
|
|
272
|
+
|
|
273
|
+
```tsx
|
|
274
|
+
import { UpdateBanner } from "@samebase/convex-hosting/react";
|
|
275
|
+
|
|
276
|
+
function App() {
|
|
277
|
+
return (
|
|
278
|
+
<>
|
|
279
|
+
<UpdateBanner message="New version!" buttonText="Reload" />
|
|
280
|
+
{/* ... */}
|
|
281
|
+
</>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
`UpdateBanner` resolves `api.hosting.getCurrentDeployment` automatically. If you re-export the query
|
|
287
|
+
under a different module name, pass it explicitly:
|
|
288
|
+
|
|
289
|
+
```tsx
|
|
290
|
+
import { api } from "../convex/_generated/api";
|
|
291
|
+
<UpdateBanner getCurrentDeployment={api.myModule.getCurrentDeployment} />;
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
For custom UI, use the hook:
|
|
295
|
+
|
|
296
|
+
```tsx
|
|
297
|
+
import { useDeploymentUpdates } from "@samebase/convex-hosting/react";
|
|
298
|
+
|
|
299
|
+
const { updateAvailable, reload, dismiss } = useDeploymentUpdates();
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Mounting under a sub-path
|
|
303
|
+
|
|
304
|
+
Mount the static site under a sub-path if you have other routes at the root:
|
|
305
|
+
|
|
306
|
+
```ts
|
|
307
|
+
app.use(hosting, { httpPrefix: "/app/" });
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
You'll also need to tell your bundler about the base path so the emitted HTML references the right
|
|
311
|
+
URLs. The CLI sets a `CONVEX_HOSTING_BASE_PATH` env var matching the component's mount when it runs
|
|
312
|
+
your build, so `vite.config.ts` can read it directly:
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
import { defineConfig } from "vite";
|
|
316
|
+
|
|
317
|
+
export default defineConfig({
|
|
318
|
+
base: process.env.CONVEX_HOSTING_BASE_PATH ?? "/",
|
|
319
|
+
});
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Root-mounted apps don't need this; the default is `/`. For webpack use `publicPath`, for Next.js
|
|
323
|
+
`assetPrefix`.
|
|
324
|
+
|
|
325
|
+
## SPA routing
|
|
326
|
+
|
|
327
|
+
By default, requests for a path with no file extension that doesn't match an uploaded file fall back
|
|
328
|
+
to `index.html`, so client-side routes like `/dashboard/settings` work on reload. For a multi-page
|
|
329
|
+
app where unknown paths should be a real 404, deploy with `--no-spa`:
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
npx @samebase/convex-hosting deploy --no-spa
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
The setting is stored with the deployment, so it travels with the code you ship rather than living
|
|
336
|
+
in a separate env var. Requests for paths with an extension (e.g. `/missing.js`) always 404 when not
|
|
337
|
+
found, regardless of this setting.
|
|
338
|
+
|
|
339
|
+
## Custom routing (SSR, prerendered pages)
|
|
340
|
+
|
|
341
|
+
`registerStaticRoutes` decides what every unmatched path returns. When your app needs to decide
|
|
342
|
+
instead, for example to server-render pages, serve prerendered pages next to an SPA shell, or
|
|
343
|
+
redirect to canonical URLs, write the catch-all route yourself and call `serveStaticAsset` for
|
|
344
|
+
uploaded files. Install the component without `httpPrefix`, as in
|
|
345
|
+
[Keep existing HTTP routes at the root](#keep-existing-http-routes-at-the-root).
|
|
346
|
+
|
|
347
|
+
```ts
|
|
348
|
+
import { httpRouter } from "convex/server";
|
|
349
|
+
import { decodeRequestPath, serveStaticAsset } from "@samebase/convex-hosting";
|
|
350
|
+
import { components } from "./_generated/api";
|
|
351
|
+
import { httpAction } from "./_generated/server";
|
|
352
|
+
|
|
353
|
+
const http = httpRouter();
|
|
354
|
+
|
|
355
|
+
http.route({
|
|
356
|
+
pathPrefix: "/",
|
|
357
|
+
method: "GET",
|
|
358
|
+
handler: httpAction(async (ctx, request) => {
|
|
359
|
+
const file = await serveStaticAsset(ctx, components.hosting, request);
|
|
360
|
+
if (file) return file;
|
|
361
|
+
|
|
362
|
+
// A missing bundle file is a 404, not a page.
|
|
363
|
+
const path = decodeRequestPath(new URL(request.url).pathname);
|
|
364
|
+
if (path === null || path.startsWith("/assets/")) {
|
|
365
|
+
return new Response("Not Found", {
|
|
366
|
+
status: 404,
|
|
367
|
+
headers: { "Cache-Control": "no-store" },
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
return await renderPage(request);
|
|
371
|
+
}),
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
export default http;
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
`serveStaticAsset` returns the file with the same headers as `registerStaticRoutes`, or `null` when
|
|
378
|
+
no file matches, including a request path with malformed percent-encoding. It never returns the
|
|
379
|
+
setup page or a 404, so your code decides what happens next. Only a found file whose storage can't
|
|
380
|
+
be read gets an error response (500). The lookup is exact: `/` is not mapped to `/index.html`, and
|
|
381
|
+
SPA fallback is off unless you pass `spaFallback: true`.
|
|
382
|
+
|
|
383
|
+
Pass `path` to serve a different file, such as a prerendered page or the SPA shell. It is the
|
|
384
|
+
decoded path of the uploaded file, starting with `/`. If your route has a prefix, remove it from
|
|
385
|
+
`path`:
|
|
386
|
+
|
|
387
|
+
```ts
|
|
388
|
+
const page = await serveStaticAsset(ctx, components.hosting, request, {
|
|
389
|
+
path: "/about/index.html",
|
|
390
|
+
});
|
|
391
|
+
const shell = await serveStaticAsset(ctx, components.hosting, request, {
|
|
392
|
+
path: "/index.html",
|
|
393
|
+
});
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
When the backend renders your pages, pushing the backend and uploading files are separate steps, so
|
|
397
|
+
right after a deploy a page can briefly refer to scripts that are not uploaded yet. That is why the
|
|
398
|
+
missing-asset response above uses `Cache-Control: no-store`: a CDN would otherwise keep serving
|
|
399
|
+
the 404.
|
|
400
|
+
|
|
401
|
+
Use `decodeRequestPath` for your own path checks, so an encoded request such as `/%61ssets/app.js`
|
|
402
|
+
still matches `/assets/`.
|
|
403
|
+
|
|
404
|
+
See
|
|
405
|
+
[`examples/tanstack-ssr/`](https://github.com/samebase/convex-hosting/tree/main/examples/tanstack-ssr)
|
|
406
|
+
for TanStack Start pages rendered in a Convex HTTP action this way.
|
|
407
|
+
|
|
408
|
+
## Switching from @convex-dev/static-hosting
|
|
409
|
+
|
|
410
|
+
This package continues `@convex-dev/static-hosting` 0.2. To switch an app:
|
|
411
|
+
|
|
412
|
+
1. Replace the dependency with `@samebase/convex-hosting`, and change every import from
|
|
413
|
+
`@convex-dev/static-hosting` to `@samebase/convex-hosting`, including `/convex.config` and
|
|
414
|
+
`/react`.
|
|
415
|
+
2. Keep the existing component instance, so the uploaded files and the site URLs stay:
|
|
416
|
+
|
|
417
|
+
```ts
|
|
418
|
+
import hosting from "@samebase/convex-hosting/convex.config";
|
|
419
|
+
|
|
420
|
+
app.use(hosting, { name: "staticHosting", httpPrefix: "/" });
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
Keep the `httpPrefix` the app used before. The code keeps using `components.staticHosting`, and
|
|
424
|
+
the CLI finds this instance without `--component`. It prints a note that the default name is now
|
|
425
|
+
`hosting`.
|
|
426
|
+
|
|
427
|
+
3. Rename `convex/staticHosting.ts` to `convex/hosting.ts`. `<UpdateBanner />` and
|
|
428
|
+
`useDeploymentUpdates()` look up `api.hosting.getCurrentDeployment` by default. To keep the old
|
|
429
|
+
file, pass `api.staticHosting.getCurrentDeployment` to them instead.
|
|
430
|
+
4. In package scripts, replace `@convex-dev/static-hosting` with `@samebase/convex-hosting` (for
|
|
431
|
+
example `npx @samebase/convex-hosting deploy`) and the bare `static-hosting` command with
|
|
432
|
+
`convex-hosting`. In the bundler config, replace `STATIC_HOSTING_BASE_PATH` with
|
|
433
|
+
`CONVEX_HOSTING_BASE_PATH`.
|
|
434
|
+
5. Deploy as usual.
|
|
435
|
+
|
|
436
|
+
To use the new default name instead, remove `name: "staticHosting"`, replace
|
|
437
|
+
`components.staticHosting` with `components.hosting`, and deploy. The new instance starts empty, so
|
|
438
|
+
the deploy uploads the files again.
|
|
439
|
+
|
|
440
|
+
An app on `@convex-dev/static-hosting` 0.1.x first follows upstream's
|
|
441
|
+
[0.1.x to 0.2.x migration guide](https://github.com/get-convex/static-hosting/blob/main/MIGRATION.md),
|
|
442
|
+
because 0.2 moved the files into the component.
|
|
443
|
+
|
|
444
|
+
## How it works
|
|
445
|
+
|
|
446
|
+
1. **Build:** your bundler emits `dist/`.
|
|
447
|
+
2. **Upload:** the CLI uses your authenticated Convex session to generate signed upload URLs, push
|
|
448
|
+
files to Convex storage, record metadata, and GC old deployments.
|
|
449
|
+
3. **Serve:** an HTTP action looks up the requested path, streams the file with the right
|
|
450
|
+
`Content-Type`, applies long-term caching for hashed assets, and falls back to `index.html` for
|
|
451
|
+
SPA routes.
|
|
452
|
+
|
|
453
|
+
## Example
|
|
454
|
+
|
|
455
|
+
See [`examples/spa/`](https://github.com/samebase/convex-hosting/tree/main/examples/spa) for a
|
|
456
|
+
complete Vite + React app, and
|
|
457
|
+
[`examples/tanstack-ssr/`](https://github.com/samebase/convex-hosting/tree/main/examples/tanstack-ssr)
|
|
458
|
+
for server rendering with TanStack Start.
|
|
459
|
+
|
|
460
|
+
```bash
|
|
461
|
+
pnpm install
|
|
462
|
+
cd examples/spa
|
|
463
|
+
pnpm run dev
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
## Contributing
|
|
467
|
+
|
|
468
|
+
See [CONTRIBUTING.md](https://github.com/samebase/convex-hosting/blob/main/CONTRIBUTING.md).
|
|
469
|
+
|
|
470
|
+
## License
|
|
471
|
+
|
|
472
|
+
Apache-2.0
|