Skip to content

feat(sites): serve a Node.js app from its folder, with Flock running its dev server - #98

Closed
omarabulkhair-66 wants to merge 10 commits into
flock-php:mainfrom
omarabulkhair-66:feat/node-sites
Closed

omarabulkhair-66 wants to merge 10 commits into
flock-php:mainfrom
omarabulkhair-66:feat/node-sites

Conversation

@omarabulkhair-66

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

Copy link
Copy Markdown
Contributor

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.

cd ~/Code/my-next-app
flock node serve                                     # npm run dev -- --port <port>, PORT set too
flock node serve --command "pnpm dev --port {port}"  # a command of its own
flock node restart
flock node unserve                                   # back to PHP

Screenshots (macOS)

A Node.js site, its dev server running on Node.js 26 A Node.js site pinned to Node 22, with its worktrees

What it does

  • config: server: "node" and an optional command on a site. A port comes from SetServer, like a FrankenPHP site's.
  • daemon:
    • Flock runs 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's node_modules/.bin is on PATH, {port} is replaced and PORT is set.
    • For next dev, Flock adds --hostname 127.0.0.1. Otherwise it listens on the LAN, past the web server's local-only guard.
    • Vite is told the site's domains through __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS.
    • The site's names are proxied to localhost:<port> (Vite may listen on IPv6 only), WebSocket upgrades included.
    • A new Node.js version, isolated or pinned, restarts the dev server.
  • status: node_server on 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.
  • supervisor: Spec.Group stops the dev server's whole process group, or its tree on Windows (taskkill /T), since npm's child holds the port.
  • worktrees: a Node.js site's worktrees run dev servers of their own. Each gets a port derived from its path (from 22000), so it stays the same while worktrees come and go.
  • share: a Node.js app's share goes to its dev server.
    • 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 .env* and .git/ are never served.
    • The share warns that visitors reach the dev server, error overlay included.
  • CLI / API / MCP: flock node serve [--command], unserve and restart. PATCH /v1/sites/{name} takes server: "node" and command. update_site set_server: node takes command. flock sites shows the Node.js version.
  • apps, all three:
    • "Node.js (npm run dev)" under Runs on, with the dev server's state, Restart, Show Log and Command.
    • What only PHP needs (document root, PHP version, extensions) is hidden.
    • The panel or tray shows the Node.js version.
    • Share is available, with its own caption.
    • In the Windows and Linux apps this builds on feat: serve a local port at a .test domain with flock proxy #87's proxy UI (a3ab9fc, 6bb8876).
  • docs: "Node.js apps" in node.md, the CLI reference and the MCP tools.

How I tested it

  • Go: make lint and make test (go test -race ./...) pass, go run ./tools/docslint passes, and GOOS=windows / GOOS=linux builds 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/.vite served, 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-in node (the test binary, serving $PORT).
      • The dev server runs, gets --port, --hostname and the Vite hosts, is served at the site's domains, and stops with its port freed.
      • A missing dev script and a pinned Node.js that isn't installed say why.
      • A worktree runs a dev server of its own.
      • A command of the site's own runs through the shell.
  • macOS: swift build and swift test pass.
  • By hand on macOS, with the branch's daemon and app installed in place of 1.0.0:
    • A Next.js 16 app on Node.js 26 and a Vite app on Node.js 22 run as sites. The browser console says [HMR] connected through Flock.
    • next dev no longer answers on the LAN address.
    • A custom command (vite --port {port} --strictPort) runs.
    • A real share (trycloudflare) of the Vite app serves the page and upgrades its HMR WebSocket, and answers 404 for /.env, /.env.local and /.git/config.
  • Windows and Linux apps: 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.
  • Not tried by hand: the Windows and Linux apps' screens, and the Windows tree stop (taskkill /T). CI builds and tests them, but nobody has clicked through them on those systems yet.

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

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

Comment thread internal/daemon/daemon.go Resolved
Comment thread internal/daemon/nodesite.go Resolved
Comment thread internal/web/share.go Resolved
Comment thread internal/cli/nodesite.go Resolved
Comment thread internal/config/worktrees.go Resolved
Comment thread internal/daemon/nodesite.go Resolved
Comment thread internal/supervisor/supervisor.go Resolved
Comment thread internal/web/share.go Resolved
@onairmarc

Copy link
Copy Markdown
Member

@omarabulkhair-66 please address copilot findings

@onairmarc onairmarc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

copilot findings

Omar Abulkhair and others added 8 commits November 4, 2026 22:33
… 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]>
- 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]>
@omarabulkhair-66

Copy link
Copy Markdown
Contributor Author

@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. go test -race ./... passes locally. Could you approve the Build run? It's waiting as "action_required" again.

@omarabulkhair-66

Copy link
Copy Markdown
Contributor Author

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

@onairmarc

Copy link
Copy Markdown
Member

@omarabulkhair-66 ill take a look tomorrow.

@onairmarc onairmarc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My comment plus any additional findings from copilot.

Comment on lines +345 to +347
public string PhpLabel => IsNode
? current.NodeServer is { } node && (node.IsRunning || node.IsStarting) ? $"Node.js {node.Version}".TrimEnd() : "Not running"
: $"PHP {Php}";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

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

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
11 resolved since last review

Review effort: Balanced

Comment thread internal/daemon/daemon.go
Comment on lines +810 to +812
if info.devServer != "" {
shares = append(shares, web.Share{Port: s.Port, DevServer: info.devServer, Domain: info.domain})
continue
Comment on lines +83 to +85
if first, _, _ := strings.Cut(strings.TrimSpace(script), " "); first == "next" {
npmArgs = append(npmArgs, "--hostname", "127.0.0.1")
}
Comment on lines +110 to +111
if !d.procUp(s.Name) && !ports.Free("127.0.0.1", site.Port) {
return fail(api.NodeFailed, "%s", ports.Describe(site.Port))
Comment thread internal/supervisor/proc_windows.go Outdated
Comment on lines +41 to +43
// 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 }
Comment thread internal/supervisor/supervisor.go Outdated
Comment on lines 235 to 237
case <-grace:
kill(cmd, p.spec.Group)
<-exited
Comment on lines +170 to +171
case !d.procUp(ns.Log):
live.State, live.Problem = api.NodeFailed, fmt.Sprintf("%s exited — see `flock logs %s`", nodeScript, ns.Log)
Comment thread linux/src/panes/sites.rs Outdated
Comment on lines +1068 to +1069
let (this, name, entry) = (self.clone(), site.name.clone(), entry.clone());
move || {
Comment thread linux/src/panes/sites.rs
Comment on lines +1070 to +1074
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() });
}
Comment on lines +851 to +852
commandDrafts[site.name] = nil
Task { await model.settings.perform { _ = try await $0.updateSite(site.name, SiteChange(command: command)) } }
Comment on lines +732 to +737
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)));
}
@onairmarc onairmarc added this to the v1.1.0 milestone Nov 7, 2026
@onairmarc

Copy link
Copy Markdown
Member

@omarabulkhair-66 Please address the referenced issues. We'd like to include this in the next Flock release scheduled for next week.

Omar Abulkhair and others added 2 commits November 8, 2026 19:34
… 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]>
@onairmarc onairmarc closed this Nov 8, 2026
@onairmarc onairmarc removed this from the v1.1.0 milestone Nov 8, 2026
@flock-php flock-php locked and limited conversation to collaborators Nov 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: serve a Node.js app (Next.js, Nuxt, Vite) as a site, with Flock running its dev server

3 participants