@@ -20,7 +20,6 @@ import {
2020 type TailscaleServeError ,
2121 type TailscaleStderrDiagnostic ,
2222} from "@t3tools/tailscale" ;
23- import { SHARED_DEV_LOOPBACK_HOST } from "@t3tools/shared/devProxy" ;
2423import * as Effect from "effect/Effect" ;
2524import * as Schema from "effect/Schema" ;
2625import type { ChildProcessSpawner } from "effect/unstable/process" ;
@@ -109,7 +108,7 @@ export type DevShareError =
109108 | DevServeFailedError ;
110109
111110/**
112- * Removes any mapping for `webPort`, reporting whether the port is now clear .
111+ * Removes the matching localhost mapping for `webPort`, preserving other handlers .
113112 *
114113 * Runs uninterruptibly: this is called from a finalizer on the way out of an
115114 * interrupted program, and cancelling the cleanup subprocess would leave
@@ -129,7 +128,7 @@ export const unshareDevServer = (
129128 ChildProcessSpawner . ChildProcessSpawner
130129> =>
131130 disableTailscaleServe ( {
132- localHost : SHARED_DEV_LOOPBACK_HOST ,
131+ localHost : "localhost" ,
133132 localPort : webPort ,
134133 servePort : webPort ,
135134 } ) . pipe (
@@ -159,7 +158,7 @@ export interface DevShareResult {
159158
160159/**
161160 * Publishes `webPort` on the tailnet at the same port number and returns the
162- * resulting HTTPS URL. Idempotent: re-running replaces any existing mapping .
161+ * resulting HTTPS URL. Reuses the matching handler and refuses other mappings .
163162 */
164163export const shareDevServer = Effect . fn ( "devShare.shareDevServer" ) ( function * ( input : {
165164 readonly webPort : number ;
@@ -171,10 +170,16 @@ export const shareDevServer = Effect.fn("devShare.shareDevServer")(function* (in
171170 return yield * new TailnetNameMissingError ( ) ;
172171 }
173172
173+ // Proxy to the hostname Vite binds rather than the package default of
174+ // 127.0.0.1. Vite listens on `localhost`, which Node 17+ resolves to `::1`
175+ // first, so it only binds the IPv6 loopback and a 127.0.0.1 target has
176+ // nothing behind it (tailscale answers 502). Passing `localhost` lets the
177+ // tailscale proxy resolve it the same way Node did. Not a literal `[::1]`:
178+ // tailscale rejects that form.
174179 yield * ensureTailscaleServe ( {
175- localHost : SHARED_DEV_LOOPBACK_HOST ,
176180 localPort : input . webPort ,
177181 servePort : input . webPort ,
182+ localHost : "localhost" ,
178183 } ) . pipe (
179184 Effect . mapError ( ( error ) => {
180185 const explanation = explainCommandFailure ( error ) ;
0 commit comments