Use the dg.run backend while you develop
Your app talks to the dg.run backend (sign-in, database, realtime, remote config) at /_dg/* on its own address. On your computer that address is http://localhost:5173, which dg.run doesn't know. Dev mode fixes that with a dev sandbox and a small reverse proxy in your dev server.
Set it up
npm create dg
Pick a template (see Start your first app). When it asks "Use the dg.run backend in dev mode?", answer yes:
- The CLI prints a login link (and opens it in your browser) with a short code.
- Log in to dg.run (or sign up), check that the page shows the same code as your terminal, and choose Allow.
- The CLI creates a dev sandbox in your account (an app without files, listed in My apps) and writes
.dg/dev.jsonin your project. That file is yours: it is already in.gitignore.
Then:
npm install
npm run dev
npm run dev now proxies /_dg/* (HTTP and WebSocket) to your sandbox. Sign in with dg.run works from localhost, users and data are real, and Data and Logs in My apps show what your dev server does.
The login link only lets the CLI create dev sandboxes in your account. It cannot read your apps' data, your wallet or anything else, and it works once, for ten minutes.
What the proxy does
- It calls the sandbox as the sandbox, because the backend knows your app by the address it is called on.
- It forwards only the app's sign-in cookie, never your other
localhostcookies. - Sign-in sends the browser back to your
localhostpage. This is allowed only for a dev sandbox and only for a loopback address on your own machine. - It does nothing in
npm run build, and does nothing when there is no.dg/dev.json. SetDG_DEV_BACKEND=0to switch it off.
In your vite.config.ts this is one line: plugins: [dgDev()], with import { dgDev } from 'dgclient/vite' (the templates already have it).
Test data and limits
- The sandbox has its own users and data, apart from your live app. Up to 3 other people besides you can sign in.
- No real money: only free trial plans, until an admin approves the app.
- Dev sandboxes count towards your 10 sandbox apps.
- Subscription proofs are signed for the sandbox's address, so
dg.billing.entitlement()cannot be verified fromlocalhostin dev mode. Test paywalls on the sandbox address after uploading a build.
Shipping it
Upload the build from the terminal:
npm run publish
It packs the app, shows a login link (open it, check the code and allow), and uploads the zip to your dev sandbox, the same project npm run dev uses. It prints the sandbox's private address; add -- --open to open it in the browser. Run it again for every new build. The login only lets the command upload builds: it cannot request a review or publish.
You can still do it by hand: npm run pack, then in My apps click Upload new build on the dev sandbox's card and choose the zip. Either way it becomes a normal sandbox build you can open on its private address; request a review in My apps when you're happy.
When you request a review the project is no longer a dev sandbox: its test data is wiped and its dev address stops working. A published project doesn't reuse it. To keep developing, make a new sandbox project:
npm run dg:sandbox
(That runs npx create-dg@latest --sandbox: a new login link, a new dev sandbox, a new .dg/dev.json.) From then on, new builds of the published app follow the sandbox-first rule: they wait in the app's sandbox until you publish them.