Skip to content

feat(cli): give the foreground Server a stable default port - #7

Merged
Patodo merged 1 commit into
mainfrom
feat/foreground-default-port
Sep 19, 2026
Merged

Patodo merged 1 commit into
mainfrom
feat/foreground-default-port

Conversation

@Patodo

@Patodo Patodo commented Sep 19, 2026

Copy link
Copy Markdown
Owner

按「放弃 daemon、改用显式前台进程 + 固定端口」的决定改的:给前台 Server 一个稳定的默认端口。

改了什么

localapp server run 原来每次都让系统分配临时端口(--port 默认 0),于是每次重启地址都变——已保存的 profile、反向代理、容器端口映射、以及「终端里显式养一个进程」这种用法都没法钉住它,只能每次把实际端口抄进客户端。

  • 默认端口改为 50524--port 保持为覆盖手段(含 --port 0,给确实想要临时端口的人)
  • CLI 帮助更新为 (default: 50524),并加了一条固定端口的示例
  • Docker 镜像本来就显式传 --port 3000,行为不变
  • docs/local-runtime.md:前台模式现在被写成与 daemon 并列的正式用法,说明它适合需要稳定地址、或本机无法注册计划任务的机器

实测(打包产物,真机)

localapp server run                          -> {"listenUrl":"http://127.0.0.1:50524"},/health 200
localapp server run --port 55441             -> 50524 释放,55441 监听,/health 200

单测 keeps one stable default port unless the operator asks for another 断言三次调用的 --port 依次是 50524 / 55441 / 0tsc --noEmit 通过。

顺带更正一处外部诊断(避免报错 bug)

上一轮的反馈里说「localapp server start 在这台机器上失败,是因为平台模板 XML 的 <Principal><UserId>」——这条不成立。我在同一台机器上做过对照实验:

  • 用平台生成的 XML 注册 → 被拒(拒绝访问)
  • LogonType 换成 InteractiveToken/Password、加/不加 UserId 共 5 种组合 → 全部被拒
  • 完全不使用 XML 的 trivial 任务 schtasks /Create /TN … /TR "cmd /c exit" /SC ONLOGON同样被拒
  • PowerShell 的 Register-ScheduledTask(另一套 API)→ 同样被拒

schtasks /Query/Run/End 在普通权限下都能用。所以限制是这台机器对非提权令牌一律拒绝创建计划任务,与 XML 内容无关;注册成功的那些任务里 UserId 是由 schtasks 自己补写的。这条不必给 localapp 报 bug。

(不过既然决定不用 daemon 了,这条路径在这台机器上是否可用已不影响你们。)

未包含

反馈里提到「localapp 0.2.8 里 sql.js 的 WASM 越界仍然存在」——那才是你们那台 Server 会死的原因,我这次没有验证也没有动它。如果要处理,我需要复现步骤或崩溃时的日志/复现条件。

`localapp server run` asked the OS for an ephemeral port on every start, so the
address changed on each restart. Anything that has to name the Server — a saved
profile, a reverse proxy, a published container port, or a terminal that keeps
one process alive — could not pin it, and the port a running Server reported had
to be copied by hand into every client.

Default to 50524 and keep `--port` as the override, including `--port 0` for
callers that really want an ephemeral port. The container image already passes
an explicit port, so its behaviour is unchanged.

The foreground mode is also a first-class way to run a personal Server when a
fixed address matters or when the machine cannot register a scheduled task:
docs/local-runtime.md now says so next to the daemon path.

Verified on the packaged build: no arguments listens on 127.0.0.1:50524 with
/health answering 200, and `--port 55441` moves it there and releases 50524.
@Patodo
Patodo merged commit c392bea into main Sep 19, 2026
3 checks passed
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.

1 participant