Skip to content

Instantly share code, notes, and snippets.

@orenaksakal
Last active September 25, 2024 00:25
Show Gist options
  • Save orenaksakal/0a588a5c0afba16de02d34cadbead6aa to your computer and use it in GitHub Desktop.
Save orenaksakal/0a588a5c0afba16de02d34cadbead6aa to your computer and use it in GitHub Desktop.
!Disclaimer: Go for hosted version always which is amazing and you will get amazing support, I'm only experimenting with this for fun. In fact I'm a pro customer
Everything including auth works but you won't get a dashboard to view and edit your data unless you create one yourself or until team opensources dashboard as well
special thanks to patte for providing docker image at https://github.com/patte/convex-backend-docker
# Guide
## Preperations
Give a read to convex provided self hosting guide at https://github.com/get-convex/convex-backend/blob/main/SELFHOSTING.md
Star the convex repo [do not skip this or else!]: https://github.com/get-convex/convex-backend
## Requirements
1) Hetzner account. referral link: https://hetzner.cloud/?ref=gnIFWawuuEOq
2) Next auth convex app template: https://github.com/get-convex/convex-nextauth-template
## Steps
1) Purchase arm64 vps (I use $5 cax11 in nuremberg) with pre selected docker ce app from the config
2) Purchase a domain or use existing one and configure dns records as `A api yourvpsip:3210` & `A http yourvpsip:321`
3) Install caddy reverse proxy to your new vps https://caddyserver.com/docs/install
4) Create a new caddy config file with `sudo nano /etc/caddy/Caddyfile`
5) add these lines as your cadd config
api.yourdomain.com {
request_body {
max_size 50MB
}
reverse_proxy 127.0.0.1:3210 {
transport http {
read_timeout 512s
}
}
}
http.yourdomain.com {
request_body {
max_size 50MB
}
reverse_proxy 127.0.0.1:3211 {
transport http {
read_timeout 512s
}
}
}
6) generate keys one by one using
export INSTANCE_SECRET=$(docker run --rm ghcr.io/patte/convex-backend generate_secret)
export ADMIN_KEY=$(docker run --rm ghcr.io/patte/convex-backend generate_key $INSTANCE_NAME $INSTANCE_SECRET | awk '/Admin Key:/{getline; print}')
export INSTANCE_NAME=flying-fox-123
note: you can modify instance name as you wish
7) run convex backend with
docker run —restart always -v ./local:/app -p 0.0.0.0:3210:3210 -p 0.0.0.0:3211:3211 ghcr.io/patte/convex-backend convex-local-backend --instance-name $INSTANCE_NAME --instance-secret $INSTANCE_SECRET
8) go back to cloned app in local and run, you need to use vps ip while developing
npx convex dev --url http://yourvpsip:3210 --admin-key "youradminkey"
9) apply patches to convex package to override .cloud domain check find all
`deploymentUrl.endsWith(".convex.cloud") && !deploymentUrl.includes("0.0.0.0")`
in node_modules/convex/dist/cjs/common/index.js
comment out those if clauses and then run
npx patch-package convex
you should have file /patches/convex+1.11.2.patch
7) run npx run dev:frontend
8) set local env variables following readme of the repo, set the NEXT_PUBLIC_CONVEX_URL as your proxied domain
9) set convex env variables following read me of the repo using
npx convex env set YOUR_ENV_VARIBLE yourvalue --admin-key "youradminkey" --url http://yourvpsip:3210
10) set convex/auth.config.ts domain as https://http.yourdomain.com
11) set convex/auth.ts const CONVEX_SITE_URL as "https://http.yourdomain.com";
12) set convex/https.ts CONVEX_SITE_URL as "https://http.yourdomain.com"
^ or use a new env variable for more optimized approach
at this state you should have the dev env working and saving your changes to remote convex on change, mutation queries auth etc all should be funtional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment