fix(console): serve dashboard/dist via local python http.server (not npm/caddy)

Prebuilt runtime ships only dashboard/dist (no package.json) so npm run
preview ENOENT-crash-loops (254). console is a local-only static backend on
127.0.0.1:17000 (dashboard is a routerless SPA); serve it with python3
-m http.server on both Linux (console.service) and macOS (console.plist) —
no second caddy (avoids clashing with the system caddy on :80; console is
local-only and not proxied by default). Gate the apt caddy install on
caddy_enabled (true on public-IP Linux VPS for the bridge ingress; macOS
installs no caddy).

Verified: debian13 + ubuntu26.04 console.service active serving 17000=200;
macOS python3 serves the same dist locally.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Haitao Pan 2026-06-24 09:44:01 +08:00
parent 3505ff1c31
commit 2ef144d572
2 changed files with 11 additions and 5 deletions

View File

@ -10,7 +10,9 @@
<string>-c</string> <string>-c</string>
<string> <string>
export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH" export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
exec /usr/bin/env npm run preview -- --host 127.0.0.1 --port {{ xworkspace_console_port }} # 预编译 runtime 只发 dashboard/dist无 package.json且 dashboard 是
# 无客户端路由的单页应用,故用 python3 静态伺服 dist 即可macOS 无 caddy
exec /usr/bin/env python3 -m http.server {{ xworkspace_console_port }} --bind 127.0.0.1 --directory "{{ xworkspace_console_dashboard_dir }}/dist"
</string> </string>
</array> </array>
<key>RunAtLoad</key> <key>RunAtLoad</key>
@ -18,7 +20,7 @@
<key>KeepAlive</key> <key>KeepAlive</key>
<true/> <true/>
<key>WorkingDirectory</key> <key>WorkingDirectory</key>
<string>{{ xworkspace_console_dashboard_dir }}</string> <string>{{ xworkspace_console_dashboard_dir }}/dist</string>
<key>StandardOutPath</key> <key>StandardOutPath</key>
<string>{{ ansible_env.HOME }}/.local/state/xworkspace/console.log</string> <string>{{ ansible_env.HOME }}/.local/state/xworkspace/console.log</string>
<key>StandardErrorPath</key> <key>StandardErrorPath</key>

View File

@ -158,7 +158,8 @@
update_cache: true update_cache: true
name: >- name: >-
{{ {{
['caddy', 'xfce4', 'python3', 'golang-go'] ['xfce4', 'python3', 'golang-go']
+ (['caddy'] if caddy_enabled | default(true) | bool else [])
+ ([xworkspace_console_browser_package] if xworkspace_console_browser_package | length > 0 else []) + ([xworkspace_console_browser_package] if xworkspace_console_browser_package | length > 0 else [])
}} }}
state: present state: present
@ -623,8 +624,11 @@
[Service] [Service]
Type=simple Type=simple
WorkingDirectory={{ xworkspace_console_dashboard_dir }} WorkingDirectory={{ xworkspace_console_dashboard_dir }}/dist
ExecStart=/usr/bin/npm run preview -- --host 127.0.0.1 --port {{ xworkspace_console_port }} # console 只是 17000 上的静态后端dashboard 为无路由单页 dist由系统
# caddy 经 /etc/caddy/conf.d/ 反代对外。用 python3 静态伺服即可,跨 Linux/
# macOS 统一、不再起第二个 caddy避免与系统 caddy 抢 :80
ExecStart=/usr/bin/env python3 -m http.server {{ xworkspace_console_port }} --bind 127.0.0.1 --directory {{ xworkspace_console_dashboard_dir }}/dist
Restart=always Restart=always
RestartSec=2 RestartSec=2