()
| 27 | } |
| 28 | |
| 29 | async function discoverServer(): Promise<ServerDiscovery> { |
| 30 | // Priority 1: Explicit env vars override everything |
| 31 | if (process.env.MUX_SERVER_URL) { |
| 32 | return { |
| 33 | baseUrl: process.env.MUX_SERVER_URL, |
| 34 | authToken: process.env.MUX_SERVER_AUTH_TOKEN, |
| 35 | }; |
| 36 | } |
| 37 | |
| 38 | // Priority 2: Try lockfile discovery (running Electron or mux server) |
| 39 | try { |
| 40 | const lockfile = new ServerLockfile(getMuxHome()); |
| 41 | const data = await lockfile.read(); |
| 42 | if (data) { |
| 43 | return { |
| 44 | baseUrl: data.baseUrl, |
| 45 | authToken: data.token, |
| 46 | }; |
| 47 | } |
| 48 | } catch { |
| 49 | // Ignore lockfile errors |
| 50 | } |
| 51 | |
| 52 | // Priority 3: Default fallback (standalone server on default port) |
| 53 | return { |
| 54 | baseUrl: "http://localhost:3000", |
| 55 | authToken: process.env.MUX_SERVER_AUTH_TOKEN, |
| 56 | }; |
| 57 | } |
| 58 | |
| 59 | // Run async discovery then start CLI |
| 60 | (async () => { |
no test coverage detected