Repository navigation
feat(sites): serve a Node.js app from its folder, with Flock running its dev server - #98
omarabulkhair-66 wants to merge 10 commits into
Conversation
f3bd3b9 to
d72e1ef
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved security flaws allow project commands to run as root, failed sites to publicly expose unrelated listeners, and shared tunnels to leak sensitive files.
11 open issues
Do not proxy or share sites whose backend preparation failed · New Apply the root-execution guard before preparing Node.js sites · New Block all .env-prefixed files and nested .git entries · New Reject FrankenPHP sites in the Node.js restart command · New Reserve configured service ports when allocating worktree ports · New Stop the outgoing backend before probing the replacement port · New Initialize custom-command metadata before Node.js resolution can fail · New Wait for process-group cleanup before completing a stop · New Keep Origin and forwarded host compatible for Server Actions · New Preserve unsaved command drafts when the site status changes · New Include Configured in NodeServer change detection · New
What changed in this PR
Adds managed Node.js sites to Flock, building on the proxy support from #87. Projects can run their dev server with a selected Node.js version while retaining site domains, HTTPS, worktrees and sharing.
Changes:
- Adds dev-server launch, status, restart and process-group shutdown support, plus worktree ports and share routing.
- Extends configuration, CLI, API and MCP interfaces for Node.js sites and proxies.
- Adds desktop controls, status displays, tests and usage documentation.
| File | Description |
|---|---|
| windows/Flock.Tray/ViewModels/SitesViewModel.cs | Tracks proxy selection and Node.js server state. |
| windows/Flock.Tray/ViewModels/PanelViewModel.cs | Adds proxy rows and Node.js status labels. |
| windows/Flock.Tray/Settings/SitesPane.xaml.cs | Adds proxy management and Node.js server controls. |
| windows/Flock.Tray/Settings/SitesPane.xaml | Displays proxy lists and creation buttons. |
| windows/Flock.Tray/Settings/SitesPane.Share.xaml.cs | Explains Node.js sharing exposure. |
| windows/Flock.Tray/Settings/SettingsWindow.xaml.cs | Supports prefilled text prompts. |
| windows/Flock.Tray/PanelWindow.xaml.cs | Opens proxy URLs from the panel. |
| windows/Flock.Tray/PanelWindow.xaml | Displays proxies and Node.js status indicators. |
| windows/Flock.Tray/Features/Sites/SitesService.cs | Adds proxy mutation operations. |
| windows/Flock.Tray.Tests/SitesWorkflowTests.cs | Tests site/proxy selection and refresh behavior. |
| windows/Flock.Kit/Settings.cs | Adds custom dev-server commands to site updates. |
| windows/Flock.Kit/Models.cs | Models proxies and Node.js server status. |
| windows/Flock.Kit/FlockClient.cs | Adds proxy API methods. |
| windows/Flock.Kit.Tests/DecodingTests.cs | Tests proxy and Node.js status decoding. |
| windows/Flock.Kit.Tests/ClientTests.cs | Tests proxy requests and Node.js command updates. |
| macos/Tests/FlockKitTests/DecodingTests.swift | Tests proxy and Node.js status decoding. |
| macos/Tests/FlockKitTests/ClientTests.swift | Tests proxy endpoint requests. |
| macos/Sources/FlockUI/Settings/SitesPane.swift | Adds proxy management and Node.js settings. |
| macos/Sources/FlockUI/PanelView.swift | Displays proxies and Node.js runtime status. |
| macos/Sources/FlockKit/Settings.swift | Adds custom commands to site updates. |
| macos/Sources/FlockKit/Models.swift | Models proxies and Node.js server status. |
| macos/Sources/FlockKit/Client.swift | Adds proxy API methods. |
| linux/src/tray.rs | Adds proxy entries and Node.js status labels. |
| linux/src/api.rs | Adds models, requests and tests for both features. |
| internal/web/web.go | Renders proxy routes and preserves upstream Host headers. |
| internal/web/web_test.go | Tests generated proxy configurations. |
| internal/web/share.go | Adds Node.js share routing and request filtering. |
| internal/web/share_serve_test.go | Tests share headers and blocked paths. |
| internal/web/pages/unlinked.html | Hides the secure-app link for proxy pages. |
| internal/supervisor/supervisor.go | Adds group-aware process shutdown. |
| internal/supervisor/supervisor_test.go | Tests stopping launcher children. |
| internal/supervisor/proc_windows.go | Adds Windows process-tree termination. |
| internal/supervisor/proc_unix.go | Adds Unix process-group signals. |
| internal/node/npm.go | Extracts reusable npm command preparation. |
| internal/mcpserver/tools_write.go | Adds proxy creation and Node.js server updates. |
| internal/mcpserver/tools_read.go | Exposes proxy and dev-server information. |
| internal/mcpserver/server.go | Extends the daemon interface for proxies. |
| internal/mcpserver/mcpserver_test.go | Tests proxy tools and Node.js server selection. |
| internal/daemon/share.go | Shares Node.js servers without asset builds. |
| internal/daemon/proxyprobe.go | Probes upstream availability and process identity. |
| internal/daemon/proxy_test.go | Tests proxy routing, upgrades and status. |
| internal/daemon/nodesite.go | Prepares dev-server processes and live status. |
| internal/daemon/nodesite_test.go | Tests Node.js launch, failure, worktrees and commands. |
| internal/daemon/frankenphp.go | Allows restarting Node.js sites. |
| internal/daemon/daemon.go | Integrates Node.js servers, proxies and shares. |
| internal/daemon/daemon_test.go | Adds a stand-in Node.js server entry point. |
| internal/config/worktrees.go | Assigns Node.js worktree settings and ports. |
| internal/config/worktrees_test.go | Tests deterministic worktree port allocation. |
| internal/config/proxies.go | Adds proxy storage and upstream validation. |
| internal/config/proxies_test.go | Tests validation, conflicts and persistence. |
| internal/config/domains.go | Reserves proxy domains against site aliases. |
| internal/config/config.go | Adds Node.js configuration and proxy-aware site discovery. |
| internal/config/config_test.go | Tests Node.js port assignment and reuse. |
| internal/cli/versions.go | Registers Node.js site commands. |
| internal/cli/status.go | Lists proxies and Node.js runtime status. |
| internal/cli/sites.go | Supports securing and unsecuring proxies. |
| internal/cli/root.go | Registers proxy commands. |
| internal/cli/proxy.go | Implements proxy creation, removal and listing. |
| internal/cli/nodesite.go | Implements serve, unserve and restart commands. |
| internal/cli/frankenphp.go | Reports Node.js site server details. |
| internal/api/configapi.go | Adds proxy endpoints and custom-command updates. |
| internal/api/api.go | Defines proxy and Node.js status responses. |
| internal/api/api_test.go | Tests proxy endpoints and Node.js configuration. |
| docs/sites.md | Documents proxy setup and behavior. |
| docs/node.md | Documents managed Node.js apps and custom commands. |
| docs/cli.md | Lists new proxy and Node.js commands. |
| docs/ai.md | Documents expanded MCP tools. |
Review effort: Balanced
|
@omarabulkhair-66 please address copilot findings |
… dev
A Next.js, Nuxt or Vite app in a project folder couldn't be a site: a
proxy only knows a port, so it had no folder, no Node.js version and no
way to start the app. A site can now run on Node.js (server "node"), next
to PHP-FPM and FrankenPHP. Flock runs `npm run dev -- --port <port>` (PORT
set too) in the folder with the site's Node.js, on a loopback port of its
own like a FrankenPHP site, restarts it when it exits and serves the
site's domains and HTTPS from it. A new Node.js version (isolated or
pinned) restarts it.
- supervisor: Spec.Group stops the process's whole group, since npm's
child (the dev server) holds the port
- daemon: the dev server's state (starting, running, failed,
unavailable), probed with the status; Vite is told the site's domains
through __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS
- cli: `flock node serve`, `unserve` and `restart`
- api / mcp: server "node" in PATCH /v1/sites/{name} and update_site
- macOS: "Node.js (npm run dev)" under Runs on, with the dev server's
state, Restart and Show Log; the panel shows its Node.js version
- docs: Node.js apps
Share isn't available for a Node.js app yet. On Windows, stopping the
dev server ends npm; its children end with the daemon (job object).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Spec.Group only stopped the process group on unix. On Windows, killing npm left its child (the dev server) holding the port until the daemon exited; taskkill /T ends the tree. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Share: a Node.js app's share goes to its dev server, which is the app.
It gets the site's own name as Host, and as Origin when there is one, so
Vite's allowed hosts and Next.js's cross-site checks (hot reload too)
take the tunnel's requests; forwarded headers are set as for PHP, and
the env files and the git repository are never served.
- Worktrees of a Node.js site run a dev server of their own, on a port
derived from the worktree's path (from 22000), so it stays the same
while worktrees come and go.
- A command of the site's own (config `command`, PATCH /v1/sites/{name},
`flock node serve --command`, update_site, Settings → Sites → Command)
runs instead of npm run dev, through the shell in the project with
node_modules/.bin on PATH; {port} becomes the port and PORT is set too.
The status shows the command that runs.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The status only had the command as it runs, {port} replaced, so the apps
prefilled Command with the port number: saving it again lost {port}.
node_server.configured is the command as set.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
As in the macOS app, so the platforms don't drift apart:
- Runs on offers Node.js (npm run dev), with the dev server's state, its
command, Restart and Show Log. The Command box is prefilled with the
site's own command as set ({port} and all), so saving it again keeps it.
- What only PHP needs is hidden for a Node.js site: the document root,
the PHP version and extensions, and the FrankenPHP notes. Share stays,
with a caption that says visitors reach the dev server.
- The panel shows a Node.js site's Node.js version, or that it doesn't run.
Flock.Kit decodes `node_server` (older daemons send none) and sends the
site's command, with tests.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
As in the macOS app, so the platforms don't drift apart:
- Runs on offers Node.js (npm run dev), with the dev server's state, its
command, Restart and Show Log. The Command box is prefilled with the
site's own command as set ({port} and all), so applying it again keeps it.
- What only PHP needs is hidden for a Node.js site: the document root,
the PHP version and extensions, and the FrankenPHP notes. Share stays,
with a caption that says visitors reach the dev server.
- The tray shows a Node.js site's Node.js version, or that it doesn't run.
The API models decode `node_server` (older daemons send none) and send the
site's command, with tests.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A dev server that can't run (its port taken, say) leaves the site's names answering 503 with why, and out of shares, instead of passing them to whatever listens on the port. - The dev server never runs as root, like a project's build scripts. - A share blocks .env* (.envrc, .env-production) and a .git file or directory at any depth. - Only the dev server's own requests (hot reload, its scripts) get the site's name as Origin, so the app's requests keep one that matches X-Forwarded-Host, as Next.js's Server Actions check. - flock node restart refuses a site that isn't a Node.js app. - Worktree ports skip ports configured for services and sites. - Switching between FrankenPHP and Node.js stops the outgoing server before the port is checked. - The site's own command is in the status even when the dev server can't run, so the apps edit it as it was set. - A group stop waits for what the launcher started, killing it after the grace period, and a launcher that exits takes its group along. - Windows and Linux keep an unsaved command across status refreshes, and Windows refreshes the editor when the command as set changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
d72e1ef to
e124827
Compare
|
@onairmarc all 11 Copilot findings are addressed in e124827 (each thread has a reply), and the branch is rebased onto main now that #87 is in, so only the Node.js commits are left. |
|
@onairmarc friendly ping: all 11 Copilot findings are addressed in e124827 (each thread has a reply), so this is ready for another look. Could the workflows also be approved so CI runs on it? #110 (for #108) builds on this PR. |
|
@omarabulkhair-66 ill take a look tomorrow. |
onairmarc
left a comment
There was a problem hiding this comment.
My comment plus any additional findings from copilot.
| public string PhpLabel => IsNode | ||
| ? current.NodeServer is { } node && (node.IsRunning || node.IsStarting) ? $"Node.js {node.Version}".TrimEnd() : "Not running" | ||
| : $"PHP {Php}"; |
There was a problem hiding this comment.
PhpLabel should only be concerned with what to display regarding PHP. If a different label needs to be displayed, then that switch logic should happen in XAML or some other method rather than a property.
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical findings can hang shutdown, leave Windows child servers running, expose development servers beyond loopback, and route public shares to unintended or insufficiently warned backends.
10 open issues
Refresh or recreate active shares when switching to Node.js · New Bind wrapped Next.js dev scripts to loopback · New Check all loopback addresses before accepting the proxy target · New Track Windows child processes after the launcher exits · New Bound post-kill process-group cleanup with a fresh deadline · New Report starting while the Node.js process is launching · New Break the entry–callback reference cycle with a weak reference · New Clear only the submitted draft after a successful update · New Keep the draft until the command update succeeds · New Preserve drafts when restart blocks or saving fails · New
11 resolved since last review
Block all .env-prefixed files and nested .git entries Apply the root-execution guard before preparing Node.js sites Do not proxy or share sites whose backend preparation failed Include Configured in NodeServer change detection Preserve unsaved command drafts when the site status changes Keep Origin and forwarded host compatible for Server Actions Wait for process-group cleanup before completing a stop Initialize custom-command metadata before Node.js resolution can fail Stop the outgoing backend before probing the replacement port Reserve configured service ports when allocating worktree ports Reject FrankenPHP sites in the Node.js restart command
Review effort: Balanced
| if info.devServer != "" { | ||
| shares = append(shares, web.Share{Port: s.Port, DevServer: info.devServer, Domain: info.domain}) | ||
| continue |
| if first, _, _ := strings.Cut(strings.TrimSpace(script), " "); first == "next" { | ||
| npmArgs = append(npmArgs, "--hostname", "127.0.0.1") | ||
| } |
| if !d.procUp(s.Name) && !ports.Free("127.0.0.1", site.Port) { | ||
| return fail(api.NodeFailed, "%s", ports.Describe(site.Port)) |
| // groupAlive is false on Windows: kill takes the whole tree at once, and a child that outlives its | ||
| // parent can't be found from it there. | ||
| func groupAlive(*exec.Cmd) bool { return false } |
| case <-grace: | ||
| kill(cmd, p.spec.Group) | ||
| <-exited |
| case !d.procUp(ns.Log): | ||
| live.State, live.Problem = api.NodeFailed, fmt.Sprintf("%s exited — see `flock logs %s`", nodeScript, ns.Log) |
| let (this, name, entry) = (self.clone(), site.name.clone(), entry.clone()); | ||
| move || { |
| let command = entry.text().trim().to_owned(); | ||
| this.command_drafts.borrow_mut().remove(&name); | ||
| if command != custom { | ||
| this.change(&name, SiteChange { command: Some(command), ..Default::default() }); | ||
| } |
| commandDrafts[site.name] = nil | ||
| Task { await model.settings.perform { _ = try await $0.updateSite(site.name, SiteChange(command: command)) } } |
| var text = command.Text.Trim(); | ||
| commandDrafts.Remove(site.Name); | ||
| if (text != saved.Trim()) | ||
| { | ||
| Start(site.Name, () => Model.Sites.UpdateAsync(site.Name, new SiteChange(Command: text))); | ||
| } |
|
@omarabulkhair-66 Please address the referenced issues. We'd like to include this in the next Flock release scheduled for next week. |
… its launcher exited When a stop ran out of grace, endGroup got the timer channel already read, so a group that stayed alive could block Stop, reload and shutdown for good. It now gets a second more. On Windows a group's launcher gets a job of its own: taskkill /T can't find a dev server once npm itself exited, the job still can. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The entry owned its activate handler, which owned the entry back, so every detail rebuild leaked the row. Co-Authored-By: Claude Opus 5.5 <[email protected]>


Fixes #97
Builds on #87 (
flock proxy, merged): rebased onto main, so only the Node.js commits are left. The review findings are addressed in e124827.What and why
A Next.js, Nuxt or Vite app in a projects folder can now be a site of its own. Its Runs on is Node.js, next to PHP-FPM and FrankenPHP. Flock runs the project's
npm run dev, or a command of the site's own, with the site's Node.js version. It runs on a loopback port of its own, like a FrankenPHP site, restarts when it exits, and serves the site's domains and HTTPS. The site keeps everything else a site has: its folder, its domains, its Node.js version (picked or pinned), worktrees and Share.Screenshots (macOS)
What it does
server: "node"and an optionalcommandon a site. A port comes fromSetServer, like a FrankenPHP site's.npm run dev -- --port <port>with the site's Node.js (node.Resolve+ npm's env), or the site's own command through the shell. In both cases the project'snode_modules/.binis on PATH,{port}is replaced andPORTis set.next dev, Flock adds--hostname 127.0.0.1. Otherwise it listens on the LAN, past the web server's local-only guard.__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS.localhost:<port>(Vite may listen on IPv6 only), WebSocket upgrades included.node_serveron the site: state (starting,running,failed,unavailable), version, port, the command that runs, whether it's the site's own command (and that command as set), the problem and the log name. The state is probed when the status is read.Spec.Groupstops the dev server's whole process group, or its tree on Windows (taskkill /T), since npm's child holds the port..env*and.git/are never served.flock node serve [--command],unserveandrestart.PATCH /v1/sites/{name}takesserver: "node"andcommand.update_siteset_server: nodetakescommand.flock sitesshows the Node.js version.flock proxy#87's proxy UI (a3ab9fc, 6bb8876).How I tested it
make lintandmake test(go test -race ./...) pass,go run ./tools/docslintpasses, andGOOS=windows/GOOS=linuxbuilds pass.supervisor: a group stop ends the launcher's child too.config: Node.js sites get a port of their own and keep it; worktree ports are stable and distinct.web: a Node.js app's share through the embedded Caddy, covering Host/Origin rewriting, forwarded headers,node_modules/.viteserved, and.env*/.git/blocked.api/mcpserver: switching to Node.js and back, and the command and its validation (one line).daemon: end to end with the embedded Caddy and a stand-innode(the test binary, serving$PORT).--port,--hostnameand the Vite hosts, is served at the site's domains, and stops with its port freed.devscript and a pinned Node.js that isn't installed say why.swift buildandswift testpass.[HMR] connectedthrough Flock.next devno longer answers on the LAN address.vite --port {port} --strictPort) runs./.env,/.env.localand/.git/config.workflow_dispatch, with the app checks' pull-request-only condition lifted on the fork's copy.taskkill /T). CI builds and tests them, but nobody has clicked through them on those systems yet.