fix(desktop): open detected ports over https when the server speaks TLS

AD
4d ago
+231-29

What & why

Opening a detected port always used http://localhost:<port>. Dev servers that serve HTTPS (for example Vite with a TLS certificate) then fail to load, and .superset/ports.json has no way to set the scheme.

This change detects the scheme when a port is opened:

  • New ports.detectScheme tRPC query in the Electron main process. It tries a TLS handshake to localhost:<port> (certificate not verified, because dev certs are usually self-signed, 500 ms timeout) and returns "https" when the handshake completes with a server certificate. Any error, timeout, or plain-HTTP server gives "http". The socket is always destroyed.
  • New renderer helper resolvePortUrl calls it and swaps http: for https: when needed. If the check fails, the original http:// URL is used.
  • Both open paths use it: the new sidebar (usePortOpenActions, including forwarded remote ports, which probe the local forwarded port) and the legacy MergedPortBadge.

The probe runs only on click, not for every listed port. The copy-URL action in the ports dropdown still copies http://localhost:<port>, because that value is computed synchronously for rendering.

How I tested it

  • New unit test detect-port-scheme.test.ts: a TLS server returns https, a plain HTTP server returns http, a TCP server that never answers the handshake returns http (timeout), and a closed port returns http. The test makes a throwaway self-signed certificate with openssl at run time, so no key is committed.
  • Ran the helper under Node 24 as well: a TLS server returns https with both 127.0.0.1 and localhost as host, a plain HTTP server returns http.
  • bun run lint: pass (after bun run lint:fix).
  • bun run typecheck in apps/desktop: pass.
  • bun test in apps/desktop with Bun 1.4.3: 8870 pass, 0 fail.

No screenshot is attached: I did not capture this from a running dev app. No user-facing strings changed.

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint and bun run typecheck pass (CI fails on lint warnings too)
  • "Allow edits from maintainers" is checked on fork PRs
  • I have signed the CLA (the bot asks on your first PR)

Summary by cubic

Opens detected dev-server ports over https:// when the server speaks TLS, instead of always using http://localhost:<port>, which broke dev servers like Vite with a certificate.

  • Probes the local port with a TLS handshake (self-signed certs accepted, 2 s timeout) at open time and falls back to http:// when the probe fails.
  • Applies to both the new sidebar and the legacy MergedPortBadge, including forwarded remote ports.
  • The copy-URL action still uses http://, since it is computed synchronously.

Summary by CodeRabbit

  • New Features
    • Local port links now detect whether a service supports HTTPS and use a secure URL when available.
    • Port links opened from the dashboard or workspace sidebar use the detected scheme, whether opened in the app or externally.
    • HTTP services and cases where scheme detection is unavailable continue to use the original URL.
  • Bug Fixes
    • Prevented repeated clicks from triggering overlapping port-opening attempts.