Skip to content

feat: serve a local port at a .test domain with flock proxy - #87

Merged
lukas-frey merged 11 commits into
flock-php:mainfrom
omarabulkhair-66:feat/proxy
Nov 4, 2026
Merged

lukas-frey merged 11 commits into
flock-php:mainfrom
omarabulkhair-66:feat/proxy

Conversation

@omarabulkhair-66

@omarabulkhair-66 omarabulkhair-66 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #73

What and why

Apps with a server of their own on a port have no .test name in Flock today, and so no trusted HTTPS origin either. That covers object storage, dashboards and dev servers, for example. This adds proxies: a .test name passed to such a server, with the interface proposed in #73.

flock proxy s3 127.0.0.1:9000 --secure   # https://s3.test → http://127.0.0.1:9000
flock proxy softpack 3000                # a port means 127.0.0.1
flock secure softpack                    # secure / unsecure work on proxies too
flock proxies                            # with what serves each one, or "not running"
flock unproxy softpack

What it does

  • config: proxies sits next to sites in config.json ({name, upstream, secured}).
    • An upstream is a port (on 127.0.0.1), host:port, or an http(s) URL without a path.
    • A proxy can't take a linked site's name or alias, and the reverse is refused too.
    • A folder of the same name in a parked folder is served by the proxy instead, as Valet and Herd do. A Node.js app usually sits there, next to the PHP ones.
  • daemon / web: each proxy is rendered like a site without a document root.
    • It gets HTTP and HTTPS, its subdomains, the local-only guard, and the site certificate when secured.
    • reverse_proxy passes the Host header unchanged (HTTPS upstreams included) and passes WebSocket upgrades (hot reload).
    • Proxy domains go into the Windows hosts file.
  • status: proxies with running, and for an upstream on this machine server. 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.
  • API: POST /v1/proxies, PATCH /v1/proxies/{name} (secured), DELETE /v1/proxies/{name}.
  • CLI: proxy, unproxy and proxies. secure/unsecure take a proxy's name, and flock sites lists proxies.
  • MCP: proxy_site (additive, like the other tools), and list_sites returns the proxies.
  • apps (macOS, Windows and Linux):
    • Settings → Sites lists proxies under the sites. For each one you can see what serves it (or "Not running"), turn on HTTPS, change its upstream, or remove it.
    • Add Proxy… adds one, and a site link (flock://site/<name> on macOS, settings/sites/<name> on Linux) selects one.
    • The panel or tray lists them after the sites.
  • docs: "Proxying a port" in sites.md, the CLI reference and the MCP tools.

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:

A running proxy

A proxy whose server isn't running

How I tested it

  • Go: make lint and make test (go test -race ./...) pass, and so does go 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_site and list_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.
  • Apps: each one has tests for decoding proxies and for its client's proxy calls; the Windows tray and the Linux tray also test their proxy rows.
    • macOS: swift build and swift test pass.
    • Windows and Linux: built and tested in CI only. I have no Windows or Linux machine. On my fork, the full Build workflow passes with every job: the Windows, macOS and Linux apps, Docs, the builds and the Go tests on all OSes (run). It ran there through workflow_dispatch, with the app checks' pull-request-only condition lifted on the fork's copy.
  • By hand on macOS, with the branch's daemon and app installed in place of 1.0.0:
    • A Next.js 15 dev server is served at http://softpack.test and over HTTPS, and /_next/webpack-hmr upgrades.
    • The app shows it as running on Node.js 22.23.4, and shows proxies with no server as not running.
    • flock secure from the terminal shows up in the app.
  • Not tried by hand: the Windows and Linux apps' screens. CI builds and tests them, but nobody has clicked through them yet.

`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]>
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

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 help wanted or assigned to you, open a new PR against main that references it (e.g. Fixes #123). See CONTRIBUTING.md.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread internal/config/proxies.go Resolved
Comment thread internal/daemon/daemon.go Resolved
Comment thread internal/web/web.go Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@onairmarc

Copy link
Copy Markdown
Member

@omarabulkhair-66 can you please address the review comments?

Omar Abulkhair and others added 4 commits November 3, 2026 21:42
- 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]>
@omarabulkhair-66

Copy link
Copy Markdown
Contributor Author

@onairmarc thanks for kicking off the review and the autofix! All three findings are addressed:

  • +3000 stored as 127.0.0.1:+3000: a port is now stored as the number (+3000 and 03000 become 3000), in 0091bcc.
  • "Secure in Flock" on an unsecured proxy's HTTPS page: that page now offers only flock secure <name> for a proxy, since the apps' flock://secure handlers know sites only (0091bcc).
  • Host header for HTTPS upstreams: your autofix commit (0ee3825) covers it. I added a comment and a Caddyfile test for it.

Testing it on a real setup turned up two more things, both in the branch now:

  • A Node.js app in a parked folder was already a "site" with no index, so flock proxy <its name> was refused. Now the proxy serves the name instead of the folder (06ab778).
  • The status now says whether a proxy's server answers, and what it is, e.g. "Node.js 22.23.4" (8f56513). The macOS app lists proxies in Settings → Sites and in the panel (d369763, 8f56513).

I updated the description with screenshots.

@onairmarc

Copy link
Copy Markdown
Member

@omarabulkhair-66 Please include the Windows and Linux versions as well. We don't want the different OS platforms to drift apart.

Omar Abulkhair and others added 2 commits November 3, 2026 23:41
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]>
@omarabulkhair-66

Copy link
Copy Markdown
Contributor Author

@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 cargo fmt fix. They do what the macOS app does: proxies in Settings → Sites (what serves them, HTTPS, upstream, remove, Add Proxy…) and in the panel/tray.

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 TestServesAShareThroughCaddy on Linux arm64, a data race inside Caddy's reverse_proxy on the PHP share path. It isn't from this PR: with go test -race -count=30 -run TestServesAShareThroughCaddy ./internal/web it races 2 times out of 30 on main too. Happy to open an issue for it.

@onairmarc

Copy link
Copy Markdown
Member

@omarabulkhair-66 thank you! yes please!

@omarabulkhair-66

Copy link
Copy Markdown
Contributor Author

@onairmarc opened #100 for the flaky TestServesAShareThroughCaddy race.

@omarabulkhair-66

Copy link
Copy Markdown
Contributor Author

@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!

@mansoorkhan96

Copy link
Copy Markdown

Thank @omarabulkhair-66 for working on this. This is the last thing i need to make the switch. Excited for trying out the flock.

@onairmarc
onairmarc self-requested a review November 4, 2026 14:57
@omarabulkhair-66

Copy link
Copy Markdown
Contributor Author

Thanks @mansoorkhan96, glad it helps! It's ready for review, so hopefully it lands soon.

@lukas-frey

Copy link
Copy Markdown
Member

Looks good, merging! I just added a page for when a proxy is not responding instead of the plain 502 page

Screenshot 2026-11-04 at 20 09 21

@lukas-frey
lukas-frey enabled auto-merge November 4, 2026 19:36
@lukas-frey
lukas-frey disabled auto-merge November 4, 2026 20:01
@lukas-frey
lukas-frey enabled auto-merge November 4, 2026 20:15
@lukas-frey
lukas-frey disabled auto-merge November 4, 2026 20:17
@lukas-frey
lukas-frey merged commit ddff58c into flock-php:main Nov 4, 2026
2 checks passed
@onairmarc onairmarc added this to the v1.1.0 milestone Nov 14, 2026 — with Copilot SWE Agent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: flock proxy to serve a local port at a .test domain over HTTPS

5 participants