Repository navigation
feat: serve a local port at a .test domain with flock proxy - #87
Conversation
`flock proxy <name> <port|host:port|url> [--secure]` serves <name>.test
(and its subdomains) from a server of its own, e.g. a Next.js, Nuxt or
Vite dev server or an object store. Caddy's reverse_proxy passes the Host
header unchanged and WebSocket upgrades through, so hot reload works.
- config: Proxies next to Sites, with NormalizeUpstream (a port means
127.0.0.1) and checks that a proxy never takes a site's name or alias
- daemon: proxies are served as rootless web sites, secured with the
site certificates; a site of the same name wins and the proxy reports
the problem; proxies are in Status and the Windows hosts file
- cli: proxy, unproxy, proxies; secure/unsecure and sites cover proxies
- api: POST /v1/proxies, PATCH and DELETE /v1/proxies/{name}
- mcp: proxy_site, and list_sites lists proxies
- docs: Proxying a port, CLI reference, MCP tools
Fixes flock-php#73
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the PR, @omarabulkhair-66! Flock takes pull requests only for issues a maintainer has approved, so this one is closed. Please open an issue describing the problem or idea first. Once it's labelled |
There was a problem hiding this comment.
🟡 Changes recommended
A leading-plus port can persist an invalid upstream URL that blocks web configuration updates, while HTTPS proxies also fail to preserve Host headers and advertise unsupported app actions.
3 open issues
What changed in this PR
Adds flock proxy to serve independently running applications at .test domains, addressing #73’s need for trusted HTTPS access to local services.
Changes:
- Adds persisted proxy configuration, validation, API endpoints, and daemon routing.
- Exposes proxies through CLI commands and MCP, with HTTPS controls and status reporting.
- Adds tests for configuration, endpoints, forwarding, WebSocket upgrades, and name conflicts, plus usage documentation.
| File | Description |
|---|---|
| internal/web/web.go | Supports reverse proxies without document roots. |
| internal/web/web_test.go | Tests proxy Caddyfile rendering. |
| internal/mcpserver/tools_write.go | Adds the proxy_site tool. |
| internal/mcpserver/tools_read.go | Includes proxies in list_sites. |
| internal/mcpserver/server.go | Extends the daemon interface for proxies. |
| internal/mcpserver/mcpserver_test.go | Tests proxy tools and listings. |
| internal/daemon/proxy_test.go | Tests forwarding, upgrades, and site precedence. |
| internal/daemon/daemon.go | Configures proxy routing, certificates, and status. |
| internal/config/proxies.go | Defines proxies and upstream validation. |
| internal/config/proxies_test.go | Tests normalization, conflicts, and persistence. |
| internal/config/domains.go | Prevents aliases from claiming proxy domains. |
| internal/config/config.go | Stores proxies and prevents site-name collisions. |
| internal/cli/status.go | Includes proxies in flock sites. |
| internal/cli/sites.go | Supports securing and unsecuring proxies. |
| internal/cli/root.go | Registers proxy commands. |
| internal/cli/proxy.go | Implements proxy management and listing commands. |
| internal/api/configapi.go | Adds proxy endpoints and client methods. |
| internal/api/api.go | Defines proxy status data. |
| internal/api/api_test.go | Tests proxy endpoint behavior. |
| docs/sites.md | Documents proxy setup and usage. |
| docs/cli.md | Adds proxy commands to the CLI reference. |
| docs/ai.md | Documents the proxy_site MCP tool. |
Review effort: Balanced
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
|
@omarabulkhair-66 can you please address the review comments? |
- A port like "+3000" is stored as 3000. Before, it was stored as "127.0.0.1:+3000", which Caddy rejects, and that blocked every later web config. - An unsecured proxy's HTTPS page offers only `flock secure <name>`. The apps' flock://secure handlers know sites, not proxies, so the "Secure in Flock" button would answer that the site is unknown. - Explain why an HTTPS upstream gets the request's Host, and test it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Proxies get a section of their own under the sites. A row shows the proxy's name, its domain and where it passes requests, plus a lock when it is secured and a warning when it isn't served. Selecting a proxy shows its URL, an HTTPS switch, its upstream (with Change…) and a button that removes it. Add Proxy… adds one by name and upstream. A flock://site/<name> link selects a proxy too. The client gets proxy, secureProxy and removeProxy, and Status decodes `proxies`, which older daemons don't send. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A Node.js app usually sits in the projects folder next to the PHP ones, so its name is already a parked site (showing "no index"), and `flock proxy softpack 3000` was refused. Now the proxy serves the name instead of the folder, as Valet and Herd do; only a linked site still blocks it. `flock unproxy` serves the folder again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A proxy only knows its port, so the apps couldn't tell a running dev server from one that isn't started (which answers 502). The status now probes each upstream, cached for a few seconds because the apps poll it: `running`, and for one on this machine `server`, e.g. "Node.js 22.23.4" when it's one of Flock's Node.js versions (Next.js renames its process, the executable stays). `flock proxies` has a SERVER column. The macOS app lists proxies in the panel after the sites, with a dot and the server or "Not running", and Settings → Sites shows the same. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@onairmarc thanks for kicking off the review and the autofix! All three findings are addressed:
Testing it on a real setup turned up two more things, both in the branch now:
I updated the description with screenshots. |
|
@omarabulkhair-66 Please include the Windows and Linux versions as well. We don't want the different OS platforms to drift apart. |
As in the macOS app, so the platforms don't drift apart: - Settings → Sites lists proxies in a group under the sites: what answers at the upstream, HTTPS, the upstream with Change…, open and remove, and Add Proxy…. - The panel lists proxies after the sites. Flock.Kit decodes `proxies` (older daemons send none) and has the POST/PATCH/DELETE /v1/proxies calls, with tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
As in the macOS app, so the platforms don't drift apart: - Settings → Sites lists proxies in a group under the sites: what answers at the upstream, HTTPS, the upstream with Change…, open and remove, and Add Proxy…. - The tray menu lists proxies after the sites. The API models decode `proxies` (older daemons send none) and shape the proxy requests, with tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@onairmarc done: the Windows and Linux apps now list proxies too. The two app commits are 66cb976 (Windows) and d98efce (Linux), and b76daef is a I don't have a Windows or Linux machine, so they're checked by CI. On my fork the whole Build workflow passes, including the Windows, macOS and Linux apps: https://github.com/omarabulkhair-66/flock/actions/runs/41734501940 The earlier failure here was |
|
@omarabulkhair-66 thank you! yes please! |
|
@onairmarc opened #100 for the flaky |
|
@onairmarc could you approve the workflow runs for this PR and #98? GitHub holds them as "action_required" since they're my first contributions here. The full Build already passes on my fork for both (#87: https://github.com/omarabulkhair-66/flock/actions/runs/41734501940, #98: https://github.com/omarabulkhair-66/flock/actions/runs/41734507020). Thanks! |
|
Thank @omarabulkhair-66 for working on this. This is the last thing i need to make the switch. Excited for trying out the flock. |
|
Thanks @mansoorkhan96, glad it helps! It's ready for review, so hopefully it lands soon. |



Fixes #73
What and why
Apps with a server of their own on a port have no
.testname in Flock today, and so no trusted HTTPS origin either. That covers object storage, dashboards and dev servers, for example. This adds proxies: a.testname passed to such a server, with the interface proposed in #73.What it does
proxiessits next tositesin config.json ({name, upstream, secured}).reverse_proxypasses the Host header unchanged (HTTPS upstreams included) and passes WebSocket upgrades (hot reload).proxieswithrunning, and for an upstream on this machineserver. That's "Node.js 22.23.4" for one of Flock's Node.js versions, else the program's name. It's probed when the status is read and cached for a few seconds.POST /v1/proxies,PATCH /v1/proxies/{name}(secured),DELETE /v1/proxies/{name}.proxy,unproxyandproxies.secure/unsecuretake a proxy's name, andflock siteslists proxies.proxy_site(additive, like the other tools), andlist_sitesreturns the proxies.flock://site/<name>on macOS,settings/sites/<name>on Linux) selects one.The review findings are fixed in 0091bcc, and the HTTPS Host fix is in the autofix commit.
Not included: extra domains for proxies.
Screenshots
Settings → Sites on macOS, with a proxy whose dev server runs, and one whose server isn't started:
How I tested it
make lintandmake test(go test -race ./...) pass, and so doesgo run ./tools/docslint.config: upstreams and their rejections, name and alias conflicts both ways, a parked folder served by the proxy, and a JSON round trip.web: the Caddyfile for plain, secured and HTTPS-upstream proxies adapts.api: the proxy endpoints.mcpserver:proxy_siteandlist_sites.daemon: end to end with the embedded Caddy. A request keeps its Host, and a WebSocket upgrade echoes through the proxy. A proxy wins over a parked folder of the same name, and one whose server is down says so.proxiesand for its client's proxy calls; the Windows tray and the Linux tray also test their proxy rows.swift buildandswift testpass.workflow_dispatch, with the app checks' pull-request-only condition lifted on the fork's copy.http://softpack.testand over HTTPS, and/_next/webpack-hmrupgrades.flock securefrom the terminal shows up in the app.