dev-code-proxy

Workflows

Local HTTPS names

Every dev server on this machine gets a stable HTTPS name, for as long as it runs. Start it the way you always do: dcp finds it and names it after its folder, or after the name in your project's config.

https://web.acme.localhost

https://
A certificate signed by a certificate authority that only this machine trusts.
web.acme
The folder's name, or the one your project's config gives it.
.localhost
Every OS sends *.localhost to this machine itself; nothing leaves it.
Only this machineMade by dcp

Why a name instead of localhost:3000

  • HTTPS like production. Secure cookies, SameSite=None, service workers, passkeys, the clipboard API and OAuth libraries that refuse plain HTTP all work.
  • Names, not ports. You open web.acme.localhost, whatever port the server picked today; with dcp run, dcp picks a free port for it, so two projects that both want port 3000 stop colliding.
  • Names that say what they are. api.acme.localhost and web.acme.localhost instead of two numbers; cookies scoped to .acme.localhost are shared between them.
  • Subdomains per tenant. With help-chat running, https://acme.help-chat.localhost reaches it too.

Set up a machine (once)

dcp service install    # the proxy from boot + the CA trusted; re-run any time, it fixes what is off
dcp service status     # three ✓ lines, exit 1 when one is off

Start your app as usual

cd ~/acme/web && npm run dev          # Vite on 5173, as always
$ dcp ls
NAME  PORT   PROVIDER    STATE        URL
web   5173   local       up           https://web.localhost
web   5173   tailscale   online       https://laptop.tail1234.ts.net/web/

The tailscale line is the same app's link online: sharing online is on by default; see Its links online.

No script changes, and nobody else on the project needs dcp. The local proxy looks for dev servers in your port range (the one in Configuration, plus 4000–4999) and gives each the name of its project folder. It looks every 10 seconds while you use the names and every minute otherwise, and it looks again the moment you open a name it doesn't know yet, so a server you just started answers on the first request. A server that stops loses its name after a few scans.

Pick the name

Put the name in the project's config, in whichever file the project already has. The first one found in the project folder wins.

{ "name": "web.acme" }

Any language. Use it for Go, Ruby, PHP without Composer, or to keep the setting out of a shared manifest.

FieldDefaultWhat it does
namethe folder's namethe app's address, https://<name>.localhost
portthe lowest portwhich listener is the app, when the project runs several servers
shareyour global modeonline: "public", "private" (Tailscale on your tailnet only, never Cloudflare) or false (neither provider)
paththe name's first labelthe app's path online, https://<machine>.ts.net/<path>/
enabledtruefalse keeps dcp away from the project entirely
scriptnonefor dcp run only (below)

dcp reads a config file only if you own it and nobody else can write it, and never looks above your home folder or inside a folder everyone can write, such as /tmp. A file it refuses or can't parse leaves the project out (nothing falls back to defaults), and dcp doctor, dcp ls and the dashboard say which file and the command that fixes it. To turn discovery off: dcp configure --discover=false.

The app receives the request with its own name as the host (Host: web.acme.localhost) and X-Forwarded-Proto: https, X-Forwarded-Host and X-Forwarded-For. Vite and Next.js accept *.localhost as they come; Django and Rails check the host:

# Django settings.py
ALLOWED_HOSTS = [".localhost"]
CSRF_TRUSTED_ORIGINS = ["https://*.localhost"]
# Rails config/environments/development.rb
config.hosts << ".localhost"

Or run it through dcp

dcp run starts the server for you on a free port it keeps for that name (4000–4999), sets PORT and HOST, and holds the name while the command runs: useful when two projects want the same port, or in scripts.

In a package.json project, keep the real command as its own script and point dev at dcp. npm run dev, pnpm dev, yarn dev and bun dev all work: the script runs with the package manager that started it.

"scripts": { "dev": "dcp run", "dev:app": "vite --port $PORT --host $HOST --strictPort" },
"dcp": { "name": "web.acme", "script": "dev:app" }

Anything else: give the name and the command. A command in one quoted string runs through the shell after dcp sets PORT and HOST; several arguments run as they are, for servers that read PORT themselves.

dcp run web.acme -- 'vite --port $PORT --host $HOST'

Astro, SvelteKit, Nuxt and React Router take the same --port $PORT --host $HOST.

dcp run setsValue
PORTa port in 4000–4999, the same for a name run after run while it is free
HOST127.0.0.1
NODE_EXTRA_CA_CERTSthe local CA, unless already set, so Node and Bun trust other .localhost names

A dcp run name wins over a found one. dcp run --force takes a name over from another terminal; DCP=0 npm run dev runs the dev:app script as it is, without dcp. The name dcp is reserved for the dashboard.

The .localhost name is for this machine. The same app is also online, for a phone, a teammate's laptop or a webhook: sharing is on by default, through Tailscale Funnel (anyone with a link; dcp tailscale on --tailnet for your tailnet only, through Serve), and through Cloudflare once you turn it on, and the proxy keeps it on after reboots (Share online). Each app has a link like https://laptop.tail1234.ts.net/web/ (and https://web-laptop.example.com through Cloudflare), the same every time, and dcp shows it next to the local name everywhere, with a way to copy it:

  • The dashboard shows a row per provider under each name, tagged local, tailscale or cloudflare, with a Copy button; the banner above the table has one row per provider: online, not online with the fix and a help link, or off with the command that turns it on (and Copy).
  • dcp ls prints a line per app and link, and dcp ls --json has each as {name, port, pid, source, dir, provider, url, state, public}; dcp url web --tailscale prints just one.
  • The desktop app's menu opens each from the app's Open section and copies it from Copy.

While a provider is off or not online yet, dcp still shows each app's link, greyed with a dashed tag and not clickable (shared: false in /api/status, not shared in dcp ls): it opens nothing until it is online (the address has no DNS record), and the banner says why and how to fix it. Tailscale needs to be signed in, the port inside the configured range, and the project must not say "share": false. A project whose config says "share": "private" stays tailnet-only even under Funnel, and off Cloudflare. The share writes what it puts online to ~/.dcp/online.json, per provider, after every look and removes it when it stops.

Restart or reload

You rarely need either: settings apply by themselves within a second, and new dev servers are found on the next scan or the moment you open their name.

dcp reload     # read the settings again and look for dev servers now
dcp restart    # a fresh copy of the proxy takes over, as a live update does

dcp restart needs no sudo and drops no request: the boot service starts a new copy of the release serving, waits until it serves, then hands over and lets the old one finish its requests. If the new copy does not start, the old one keeps serving and the error says why. The boot service's supervisor answers it from launcher revision 4 (dcp 1.21.1): one installed earlier says so, and dcp service install updates it once (it asks for your password; dcp doctor notes it). Sharing online restarts with it; its Tailscale entry and Cloudflare tunnel stay in place throughout.

The dashboard

https://dcp.localhost shows what runs (how each was started, port, folder, uptime, its links online per provider), the CPU and memory of each app with every process it started (macOS, Linux), requests, failures and p50/p95 per name, the proxy's version, live updates and set-aside releases, discovery and update status, and any config file it skipped, with how to fix it. It updates itself every few seconds and is reachable only from this machine. The same data as JSON for scripts and agents: https://dcp.localhost/api/status (sharing per provider in proxy.sharing.tailscale and proxy.sharing.cloudflare, each app's links in links.tailscale and links.cloudflare: {url, public, shared}). It is on by default; dcp configure --dashboard=false turns it off, and dcp.localhost then answers like any name nothing serves.

Stop an app

A dev server left running in a forgotten terminal holds its port. Stop it by name or by port:

dcp stop web.acme        # the app at https://web.acme.localhost
dcp stop 3000            # whatever listens on port 3000
dcp stop web.acme --force

dcp stop shows what it is about to end (process, pid, CPU and memory, how long it has run, port, folder) and the command it runs, then asks. It sends SIGTERM, as Ctrl-C in the app's terminal would, and waits up to 5 seconds for it and the processes it started to exit; a dcp run app ends with its dcp run. For an app that hangs, --force ends it and every process it started at once (SIGKILL), with no chance to clean up. On Windows it runs taskkill /PID <pid> /T, and /F with --force. --yes skips the question, for scripts and agents.

On the dashboard, each app has a Stop button. It opens the same summary, with Stop and Force stop side by side, the exact command each runs, and the commands that do the same in a terminal on this OS, each with a copy button. A name whose process exited shows exited: dcp keeps a found name for a few scans in case it restarts.

macOS, LinuxWindows
Stopkill <pid>taskkill /PID <pid> /T
Forcekill -9 <pid>taskkill /PID <pid> /T /F
By portlsof -ti tcp:<port> -sTCP:LISTEN | xargs killGet-NetTCPConnection -LocalPort <port> -State Listen | ForEach-Object { Stop-Process -Id $_.OwningProcess }

The same through the API: GET https://dcp.localhost/api/apps/<name> returns what a stop would end and how, and POST https://dcp.localhost/api/apps/<name>/stop with {"force": false} stops it (200 when it exited, 409 with the forced command when it did not). Only the dashboard's own page can stop an app from a browser: dcp refuses a request another website sends (it checks Sec-Fetch-Site and Origin, and asks for a JSON body, which a form cannot send). On macOS and Linux the request must also come from one of your own programs: dcp looks up the other end of that very connection and stops nothing for another account on the same machine. Windows offers no cheap way to check that, so there the dashboard shows the commands to copy, and dcp stop does the stopping in a terminal. dcp never stops itself, a process another user owns, or Docker: for a container's port it names the container to docker stop instead.

Names nothing serves

By default dcp answers only the names it serves: the apps it found or runs (and their subdomains) and the dashboard. A name nothing serves gets no answer, as if nothing listened, so a typo looks like a server that is not running. dcp still looks again before it gives up, so a server started a moment ago answers on the first request.

With the catch-all on (dcp configure --catch-all), dcp answers every .localhost name: one nothing serves shows the names that do run and how to start an app under that one. Either way, a name whose app stopped answering shows its port, process, folder and the likely cause. A browser gets a page, curl gets the same as text. Both settings apply to the running proxy within a second, without a restart, as do --discover and --local-request-log; the ports, runtimes and Docker setting apply from the next scan.

Plain HTTP

http:// gets what https:// gets. Every http://<name>.localhost that https answers, dcp included, redirects to the same URL over https (308: the method and body are kept), so a browser shows the very same page. http://localhost/ and http://127.0.0.1/ open the dashboard, like https://localhost/. A name https does not answer gets no answer on http either. With the catch-all on, any other host that reaches port 80 gets a short 404 that lists nothing, so a website whose name was re-pointed at 127.0.0.1 (DNS rebinding) learns nothing about this machine. If another program holds port 80, HTTPS keeps working and dcp doctor names the program.

Subdomains

A name also answers for its subdomains: with help-chat running, https://acme.help-chat.localhost reaches it too (the nearest registered parent wins), for apps that serve one tenant per subdomain.

Need the same app online, for a webhook or a phone? A dcp run app is a dev server like any other: dcp finds it and gives it a link through Tailscale too. See Share online.

Technical details

  • Found servers live in the proxy's memory: each scan lists the listening sockets in the port range with their process (reusing what it learned about each process, so an idle scan costs one lsof), keeps the web runtimes, finds each one's project folder and config, and maps names to ports. A project that runs several servers gets its main name on the lowest port (or the config's port) and <name>-<port> for the others.
  • dcp run names are one JSON file per running app in ~/.dcp/routes/<name>.json ({name, port, pid, dir}) and a lock its process holds. Both go when the run ends, and the proxy drops the name of a run killed with kill -9 the next time it reads the folder, which it does only when the folder changes.
  • Certificates: a local CA in ~/.dcp/ca/ (ECDSA P-256, 10 years, key 0600) signs one certificate per exact name on first use (90 days, renewed in memory). The CA carries a name constraint for localhost: it cannot sign a certificate for any other domain that a browser would accept. Names outside .localhost get no certificate, and the cache is bounded.
  • The service is a small supervisor that runs as root for one job: opening 127.0.0.1:443 and [::1]:443, which an ordinary process cannot do. It then switches to your user for good, keeps the sockets open for its whole life, and runs the proxy as a worker from your own copy of dcp in ~/.dcp/bin. Root never runs a file you can write, and every file the proxy writes stays yours. While no worker runs, the supervisor serves the names itself, so they keep working. macOS: a launchd daemon (/Library/LaunchDaemons/com.meabed.dev-code-proxy.plist, log /var/log/dev-code-proxy.log). Linux: a systemd unit (dev-code-proxy.service, journalctl -u dev-code-proxy).
  • Updates without a password or a dropped request: any newer dcp you run copies itself into ~/.dcp/bin (never an older one), and the proxy checks for a release once a day and verifies it against the release's checksums.txt. The supervisor starts the new version beside the serving one on the same sockets; once it answers a real HTTPS request it takes over and the old worker drains. A version that fails, or crashes within its first minute, is recorded as set aside in bin/state.json and never used again; the previous worker keeps serving. A crashing worker restarts with backoff. sudo is needed again only if the supervisor itself changes, which dcp doctor says. dcp run in a terminal sets up a machine that has no proxy yet; in CI or a pipe it only warns.
  • Trust: dcp service install ends with it (or dcp trust alone). macOS adds the CA to your login keychain (one password dialog at the screen; over SSH it is left as a next step). Debian/Ubuntu: /usr/local/share/ca-certificates + update-ca-certificates; Fedora/RHEL: /etc/pki/ca-trust/source/anchors + update-ca-trust. Windows: the user's Root store (certutil -user).
  • Every command and flag: Commands
  • A name that doesn't answer, a certificate warning, port 443 taken: Troubleshooting
  • The same app online, for webhooks and phones: Share online