Cloudflare setup
Create the Cloudflare resources for a self-hosted GoPayLocal, write wrangler.toml from the example, set secrets, and deploy the API, the dashboard and the admin app.
This page deploys the API Worker and the dashboard (and optionally the admin app) to your Cloudflare account. Do Database and migrations first, or at least create the database, because Hyperdrive needs its connection string.
Examples use example.com; replace it with your domain. All pnpm wrangler commands run from apps/api and use the Wrangler version pinned in the repository.
1. Get the code
Section titled “1. Get the code”Fork the repository if you want to keep your configuration in Git (recommended), then clone your fork or the original:
git clone https://github.com/RayLabsHQ/gopaylocal.gitcd gopaylocalcorepack enablepnpm installcorepack enable is needed once per machine; it makes pnpm the exact version pinned in package.json. Node 26 does not include Corepack: run npm install -g corepack first.
2. Sign in to Cloudflare
Section titled “2. Sign in to Cloudflare”cd apps/apipnpm wrangler loginThis opens a browser to authorize Wrangler for your account.
3. Create Hyperdrive and the KV namespaces
Section titled “3. Create Hyperdrive and the KV namespaces”Start your configuration from the example. It replaces the wrangler.toml that ships in the repository, which holds the hosted service’s resource ids:
cp wrangler.example.toml wrangler.tomlCreate a Hyperdrive configuration for your database:
pnpm wrangler hyperdrive create gopaylocal-db \ --connection-string="postgres://USER:PASSWORD@HOST:5432/DATABASE?sslmode=require"Create the two KV namespaces:
pnpm wrangler kv namespace create CACHEpnpm wrangler kv namespace create VPN_DATAEach command prints an id. Paste them into wrangler.toml in place of <HYPERDRIVE_ID>, <CACHE_KV_ID> and <VPN_DATA_KV_ID>. Keep the binding names (HYPERDRIVE, CACHE, VPN_DATA) exactly as they are; the code reads them by name.
4. Fill in the rest of wrangler.toml
Section titled “4. Fill in the rest of wrangler.toml”In the [vars] section:
API_BASE_URL: the public URL of the API, for examplehttps://api.example.com. Sign-in callbacks and provider webhooks use it.APP_BASE_URL: the public URL of the dashboard, for examplehttps://app.example.com.ADMIN_BASE_URL: the public URL of the admin app, if you deploy it.SELF_HOSTED = "true": leave it as it is.
You decide these URLs now, before anything is deployed. They must be on one domain; see Domains and sign-in cookies.
Also check:
- Rate limiters. The nine
[[ratelimits]]blocks need nothing created. Theirnamespace_idvalues (1001to1009) must be unique within your Cloudflare account, so change them if another Worker in the account already uses those numbers. - Cron triggers. Keep all three. On Workers Free, the daily VPN refresh cannot finish; see Cloudflare plan and step 9.
- Placement. The commented-out
[placement]block can run the Worker near your database. Cloudflare marks host-based placement as experimental (Placement). It is optional. - Custom Domain. To serve the API on
api.example.com, uncomment theroutesline near the top. See step 10.
Configuration reference explains every entry.
5. Set the secrets
Section titled “5. Set the secrets”openssl rand -base64 32 # run once per secret and paste the output when askedpnpm wrangler secret put BETTER_AUTH_SECRETpnpm wrangler secret put TOKEN_ENCRYPTION_KEYThe first secret put asks whether to create the Worker, because it does not exist yet. Answer yes.
Add the OAuth credentials as well; OAuth setup shows how to get them:
pnpm wrangler secret put GITHUB_CLIENT_IDpnpm wrangler secret put GITHUB_CLIENT_SECRETpnpm wrangler secret put GOOGLE_CLIENT_IDpnpm wrangler secret put GOOGLE_CLIENT_SECRETLeave the Dodo Payments secrets unset; self-hosted mode does not use them.
6. Build the banner and deploy the API
Section titled “6. Build the banner and deploy the API”Apply the migrations if you have not yet (Database and migrations). Then, from the repository root:
pnpm build:bannercd apps/apipnpm run deploypnpm build:banner creates packages/banner/dist/banner.js. The deploy copies it into apps/api/static, which Cloudflare serves as static files (/v1/banner/script.js). Without the build, the deploy stops with a message that says to run it. Build it again after every update.
To migrate, sync admins and deploy in one step, use pnpm run deploy:full instead (details).
Check that the API answers (use the workers.dev URL Wrangler printed, or your API hostname once step 10 is done):
curl https://api.example.com/health# {"status":"ok","timestamp":"..."}7. Build and deploy the dashboard
Section titled “7. Build and deploy the dashboard”The dashboard is a static app. The API URL is compiled into it, so set VITE_API_URL when you build. Without it, the build points at http://localhost:8787. From the repository root:
VITE_API_URL=https://api.example.com pnpm --filter @gopaylocal/dashboard buildpnpm --filter @gopaylocal/dashboard run deploy:workerapps/dashboard/wrangler.toml needs no changes. apps/dashboard/wrangler.example.toml shows the optional Custom Domain setting.
8. Build and deploy the admin app (optional)
Section titled “8. Build and deploy the admin app (optional)”VITE_API_URL=https://api.example.com pnpm --filter @gopaylocal/admin buildpnpm --filter @gopaylocal/admin run deploy:workerOnly users with the admin role can use it; see First admin user.
9. Load the VPN data
Section titled “9. Load the VPN data”- Workers Paid: the daily cron (
30 9 * * *, UTC) loads and refreshes the data. Nothing to do. - Workers Free: let the daily GitHub Actions job do it (VPN detection: refresh from GitHub Actions), or build the dataset on your computer and upload it with Wrangler now and then (by hand).
Until the data is loaded, VPN detection only checks the visitor’s network against a built-in list of datacenter and VPN networks.
10. Use your own hostnames
Section titled “10. Use your own hostnames”Each Worker is reachable on its workers.dev hostname after deploy. To use your domain (whose zone must be active on Cloudflare), either:
- add a Custom Domain to each Worker in the Cloudflare dashboard (Workers & Pages > your Worker > Settings > Domains & Routes), or
- uncomment the
routesentry in that app’swrangler.tomland deploy again.
See Custom Domains. If a hostname changes, update API_BASE_URL, APP_BASE_URL or ADMIN_BASE_URL in apps/api/wrangler.toml, redeploy the API, and rebuild the dashboard and admin app with the new VITE_API_URL.
Next steps
Section titled “Next steps”-
OAuth setup, if you have not created the OAuth app yet.
-
Create a product, a campaign and an API key in the dashboard, and add the banner to a page. In the script tag, use your own API hostname:
<script src="https://api.example.com/v1/banner/script.js?key=YOUR_PUBLIC_KEY" async></script>The campaign page in the dashboard shows this snippet with your key, product id and API hostname filled in. It takes the hostname from the
VITE_API_URLthe dashboard was built with. See Banner installation.The JavaScript SDK and the React provider default to the hosted API. Pass your API URL as
apiBase:new GoPayLocal({ apiKey, apiBase: 'https://api.example.com' }), or<GoPayLocalProvider apiKey={...} apiBase="https://api.example.com">. See JS SDK and React provider.