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

+21
View File
@@ -203,6 +203,27 @@ class Client {
: path;
}
/// The dev servers the host discovered, for the browser panel's preview
/// list. [directory] scopes the discovery to a space's own listener.
Future<List<DevServerInfo>> devServers({String? directory}) async {
final r = await _json('GET', '/api/dev-servers', directory: directory);
return [
for (final e in (r['servers'] as List? ?? []))
if (e is Map<String, dynamic>) DevServerInfo.fromJson(e),
];
}
/// A short-lived token for WebSocket upgrades that cannot carry the bearer
/// header. The dev tunnel appends it as `oc_url_token`.
Future<({String token, int expiresIn})> mintUrlToken() async {
final r = await _json('POST', '/auth/url-token');
final expires = r['expiresIn'];
return (
token: r['token'] as String? ?? '',
expiresIn: expires is num ? expires.toInt() : 240,
);
}
/// The server's home and chats root. Sessions filed under a chats root are
/// the "聊天" group, not a project; the root can be relocated away from the
/// home config directory, so it must come from the server.