087b2230c4
Users pasting a Tailscale IP or LAN host as 'host:port' (no http://) hit either a hard 'URL is not valid' error in the main process or, worse, a silent dead probe in the renderer: the ^https?:// gates in the settings and first-run forms never fired, so the field sat idle with no feedback. - normalizeRemoteBaseUrl() (electron/connection-config.ts) now prepends http:// when the input has no scheme:// prefix; explicit non-http schemes (ws://, ftp://) still reach the protocol check and get a clear rejection. - New renderer twin coerceRemoteUrlScheme() (src/lib/remote-url.ts), wired into both probe gates (gateway-settings.tsx and first-run-remote-form.tsx) so the debounced /api/status probe, sign-in, test, and save all see the coerced URL. - Tests for both sides (electron/connection-config.test.ts, src/lib/remote-url.test.ts).
23 lines
822 B
TypeScript
23 lines
822 B
TypeScript
/**
|
|
* remote-url.ts
|
|
*
|
|
* Renderer-side twin of the scheme coercion in
|
|
* electron/connection-config.ts `normalizeRemoteBaseUrl()`. Users routinely
|
|
* paste scheme-less "host:port" (a Tailscale IP, a LAN hostname) into the
|
|
* remote-gateway URL field; without coercion the renderer's `^https?://`
|
|
* probe gates never fire and the field just sits idle with no feedback.
|
|
*
|
|
* Keep the opt-out regex in sync with the electron side: only a real
|
|
* `scheme://` prefix skips the http:// prepend, so explicit non-http schemes
|
|
* (ws://, ftp://) still reach main-process validation and get a clear error.
|
|
*/
|
|
export function coerceRemoteUrlScheme(rawUrl: string): string {
|
|
const value = String(rawUrl || '').trim()
|
|
|
|
if (!value || /^[a-z][a-z0-9+.-]*:\/\//i.test(value)) {
|
|
return value
|
|
}
|
|
|
|
return `http://${value}`
|
|
}
|