@@ -83,144 +83,7 @@ connect to Postgres.
83
83
84
84
# Self Hosting with [ Fly.io] ( https://fly.io/ )
85
85
86
- ## Setup
87
-
88
- Copy the
89
- [ ` self-hosted ` files] ( https://github.com/get-convex/convex-backend/tree/main/self-hosted )
90
- to your local machine. You don't need to copy it into your project directory,
91
- but you can.
92
-
93
- ``` sh
94
- npx degit get-convex/convex-backend/self-hosted ./self-hosted
95
- cd self-hosted
96
- ```
97
-
98
- Note: ` degit ` is a tool for copying files from git repositories.
99
-
100
- ## Deploying the backend to Fly.io
101
-
102
- The backend "deploy" can mean two things:
103
-
104
- 1 . Deploying the Convex docker image to Fly.io.
105
- 2 . Deploying your app's Convex functions to the fly machine running Convex.
106
-
107
- Steps:
108
-
109
- 1 . Deploy the backend to Fly.io.
110
-
111
- ``` sh
112
- fly launch
113
- ```
114
-
115
- Future deployments can be done with ` fly deploy ` .
116
-
117
- 2 . Note the URL of the app that gets printed out, which will be of the form
118
- ` https://<app-name>.fly.dev ` (no trailing slash).
119
-
120
- In the fly.toml file, change the env variables ` CONVEX_CLOUD_ORIGIN ` and
121
- ` CONVEX_SITE_ORIGIN ` to:
122
-
123
- ``` sh
124
- CONVEX_CLOUD_ORIGIN=" <fly app url>"
125
- CONVEX_SITE_ORIGIN=" <fly app url>/http"
126
- ```
127
-
128
- And re-deploy to pick up the changes.
129
-
130
- ``` sh
131
- fly deploy
132
- ```
133
-
134
- Copy and paste the fly url to set ` NEXT_PUBLIC_DEPLOYMENT_URL ` in the
135
- dashboard/fly.toml file. 3. Generate an admin key.
136
-
137
- ``` sh
138
- fly ssh console --app self-hosted-backend --command " ./generate_admin_key.sh"
139
- ```
140
-
141
- Unless you edited the app's ` fly.toml ` , the name is ` self-hosted-backend ` . If
142
- you specified a different name, replace ` self-hosted-backend ` with it.
143
-
144
- This admin key will be used to authorize the CLI and access the dashboard.
145
-
146
- 4 . Inside your app, create a ` .env.local ` file with the following variables:
147
-
148
- ``` sh
149
- CONVEX_SELF_HOST_URL=' <url-to-your-fly-backend>'
150
- CONVEX_SELF_HOST_ADMIN_KEY=' <your-admin-key>'
151
- ```
152
-
153
- 5 . To deploy your Convex functions to the backend, you'll use the ` convex ` CLI.
154
-
155
- In your frontend app directory, install ` convex ` .
156
-
157
- ``` sh
158
- npm install convex@alpha
159
- ```
160
-
161
- To continuously deploy code for development:
162
-
163
- ``` sh
164
- npx convex self-host dev
165
- ```
166
-
167
- This will continuously deploy your functions as you edit them. It will also
168
- set environment variables for your frontend, like` VITE_CONVEX_URL ` . If you
169
- only want to deploy once, run ` npx convex self-host dev --once ` .
170
-
171
- To deploy code once, e.g. for production:
172
-
173
- ``` sh
174
- npx convex self-host deploy --env-file < path to env file>
175
- ```
176
-
177
- If you don't want to ues a path, call it with the env variables set. It will
178
- not read any .env file by default.
179
-
180
- ** Note:** It's up to you whether a backend is for development or production.
181
- There is no distinction within the instance. If you only have one backend,
182
- you can run ` npx convex self-host dev ` or ` npx convex self-host deploy `
183
- depending on whether you want it to live-update or not.
184
-
185
- An extension of this is that you can have many backends for staging or
186
- previews. The difference will be in the environment variables.
187
-
188
- ### HTTP Actions
189
-
190
- Note that HTTP actions run on your fly app url under the ` /http ` path. For
191
- example:
192
-
193
- - If your fly app is deployed at ` https://self-hosted-backend.fly.dev `
194
- - And you have an HTTP action named ` /sendEmail `
195
- - You would call it at ` https://self-hosted-backend.fly.dev/http/sendEmail `
196
-
197
- ## Deploying the dashboard to Fly.io
198
-
199
- The dashboard allows you to see logs, read/write data, run functions, and more.
200
- You can run the dashboard locally (see [ SELFHOSTING.md] ( SELFHOSTING.md ) ), or
201
- also deploy it to Fly.io.
202
-
203
- 1 . Go into the dashboard directory where you copied the self-hosted files.
204
-
205
- ``` sh
206
- cd self-hosted/dashboard
207
- ```
208
-
209
- 2 . Update ` NEXT_PUBLIC_DEPLOYMENT_URL ` in the dashboard/fly.toml file to the url
210
- of your fly-hosted backend, if you haven't already.
211
-
212
- 3 . Deploy the dashboard to Fly.io.
213
-
214
- ``` sh
215
- fly launch
216
- ```
217
-
218
- You should now be able to visit the dashboard at the url output by fly.
219
-
220
- 4 . Visit the dashboard and enter the admin key. To log in, it will need the
221
- admin key you generated earlier.
222
-
223
- You should see your tables, see and run functions, etc.
86
+ See the [ Fly instructions] ( ./fly/README.md )
224
87
225
88
# Self Hosting on Postgres with [ Neon] ( https://neon.tech )
226
89
0 commit comments