feat: preview the host's dev servers through the dev tunnel

- loopback dev-server URLs are no longer opened on the phone's network: the
  panel binds a local 127.0.0.1 TCP listener and pipes each connection over
  an authenticated WebSocket to the host's /api/dev-tunnel, which dials its
  own loopback port; the WebView keeps the original address in the bar while
  the page, absolute URLs, cookies and HMR sockets use the tunneled origin
- the empty state lists /api/dev-servers results for the project (only ports
  that answered with a web page), with title, URL and command; tapping one
  opens it through the tunnel
- relay transports mint oc_url_token themselves; a direct connection mints
  and caches /auth/url-token and also sends the bearer
- a new loopback port opened from a tunnelled page gets its own tunnel
- version 0.7.1+701; tests cover the URL mapping and tunnel helpers
This commit is contained in:
blumia committed 2026-12-04 12:21:09 +08:00
1 parent 318276d3b9
commit 695d27cdd7
12 files changed
+545 -39

No files matched your search

+34
View File
@@ -1107,3 +1107,37 @@ class ServerVersions {
final String openchamber;
const ServerVersions({this.opencode = '', this.openchamber = ''});
}
/// A dev server the OpenChamber host discovered (`GET /api/dev-servers`).
/// [url] is the address to preview (usually a loopback URL on the host); the
/// browser tunnels its port through `/api/dev-tunnel`.
class DevServerInfo {
final int port;
final String url;
final String command;
final String directory;
final String title;
const DevServerInfo({
this.port = 0,
this.url = '',
this.command = '',
this.directory = '',
this.title = '',
});
factory DevServerInfo.fromJson(Map<String, dynamic> j) {
final page = j['page'];
return DevServerInfo(
port: (j['port'] as num?)?.toInt() ?? 0,
url: j['url'] as String? ?? '',
command: j['command'] as String? ?? '',
directory: j['directory'] as String? ?? '',
title: page is Map && page['title'] is String
? (page['title'] as String).trim()
: '',
);
}
String get label => title.isNotEmpty ? title : (url.isNotEmpty ? url : ':$port');
}