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

+4 -2
View File
@@ -42,8 +42,10 @@ void main() {
testWidgets('the browser tab shows the mobile-only hint on desktop',
(tester) async {
await tester.pumpWidget(const MaterialApp(
home: Scaffold(body: BrowserPanel()),
final app = AppState();
addTearDown(app.dispose);
await tester.pumpWidget(MaterialApp(
home: Scaffold(body: BrowserPanel(app: app, directory: '/home/me')),
));
await tester.pumpAndSettle();
+43
View File
@@ -0,0 +1,43 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:openchamber/api/dev_tunnel.dart';
void main() {
test('loopback hosts and ports are recognised', () {
for (final host in [
'localhost',
'127.0.0.1',
'::1',
'[::1]',
'0.0.0.0',
'::',
]) {
expect(isLoopbackDevHost(host), isTrue, reason: host);
}
expect(isLoopbackDevHost('192.168.1.10'), isFalse);
expect(devServerPort(Uri.parse('http://localhost:5173/')), 5173);
expect(devServerPort(Uri.parse('http://127.0.0.1')), 80);
expect(devServerPort(Uri.parse('https://localhost')), 443);
expect(devServerPort(Uri.parse('https://example.com:8443')), isNull);
});
test('the tunnel keeps path, query and fragment', () {
final local = localTunnelUri(
Uri.parse('http://localhost:5173/a/b?x=1#top'), 4000);
expect(local.toString(), 'http://127.0.0.1:4000/a/b?x=1#top');
});
test('the address bar is mapped back to the dev server', () {
expect(
displayUrlFor('http://127.0.0.1:4000/a', 4000, 'http://localhost:5173'),
'http://localhost:5173/a',
);
expect(
displayUrlFor('http://127.0.0.1:4000', 4000, 'http://localhost:5173'),
'http://localhost:5173',
);
expect(
displayUrlFor('https://example.com/x', 4000, 'http://localhost:5173'),
'https://example.com/x',
);
});
}