Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(web): allow tailnet hosts on the HTTPS dev server (#7693)

teo7d18b3b59356
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 96b05fb989..038b1c5993 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -19,6 +19,7 @@ cd apps/web && PORT=3003 bun run dev # any free port in 3000-3009
`import.meta.env.MODE === 'development'` resolves the service clients to `https://dev.macro.com` through Vite’s same-origin development proxy. Sign in on the development hostname; existing `.macro.com` cookies are separate. Vite prints `https://<hostname>:<port>/app/`; `https://localhost:<port>/app/` also works. Trust `infra/local/certs/ca.pem` once in the visiting browser (see `infra/local/certs/README.md`). `MACRO_DEV_HTTPS=false` restores HTTP for workflows that require it. Notes:
+- On a remote devbox, open the app through Tailscale Serve rather than `https://<hostname>:<port>`. Vite drops to HTTP/1.1 while its development proxy is on, so the browser fetches the ~7k dev modules six at a time and pays a round trip for each (about 45 s at 30 ms). Run `sudo tailscale serve --bg --https=443 https+insecure://localhost:<port>` on the devbox and open `https://<devbox>.<tailnet>.ts.net/app/`, which serves HTTP/2 with a trusted certificate. Sign in again there. Serve offers HTTPS ports 443, 8443, and 10000.
- Never assume port 3000 or 3002 is yours. Check with `lsof -nP -iTCP:<port> -sTCP:LISTEN -t` and confirm the owner's worktree via `lsof -p <pid> | awk '$4=="cwd"'`. Take a free port instead of killing another session's server, and reuse one only if its cwd is this worktree.
- The `.cursor/*.sh` scripts and the `run-app` skill are **Cursor Cloud** entry points. On a local machine they prompt for sudo and are the wrong tool. Only backend (Rust) changes need the local stack.
diff --git a/apps/web/scripts/dev-https.test.ts b/apps/web/scripts/dev-https.test.ts
index 54b8fc4312..368b5235b9 100644
--- a/apps/web/scripts/dev-https.test.ts
+++ b/apps/web/scripts/dev-https.test.ts
@@ -55,16 +55,17 @@ it('serves HTTPS and HMR with the existing CA and detected hostname', async () =
});
await expect(fetchPage(hostname, false)).rejects.toThrow();
- // A real TLS WebSocket upgrade with Vite's browser origin/token checks.
- const protocol = await new Promise<string | undefined>(
- (resolve, reject) => {
+ // A real TLS WebSocket upgrade with Vite's browser origin/token checks,
+ // resolving to the negotiated protocol or the rejection status.
+ const upgradeHmr = (host: string) =>
+ new Promise<string | undefined>((resolve, reject) => {
const req = request({
...options,
servername: hostname,
path: `/?token=${vite.config.webSocketToken}`,
headers: {
- host: `${hostname}:${address.port}`,
- origin: `https://${hostname}:${address.port}`,
+ host,
+ origin: `https://${host}`,
connection: 'Upgrade',
upgrade: 'websocket',
'sec-websocket-version': '13',
@@ -78,16 +79,22 @@ it('serves HTTPS and HMR with the existing CA and detected hostname', async () =
req.on('error', reject);
req.on('response', (res) => {
res.resume();
- reject(new Error(`HMR returned ${res.statusCode}`));
+ resolve(`HTTP ${res.statusCode}`);
});
req.on('upgrade', (res, socket) => {
socket.destroy();
resolve(res.headers['sec-websocket-protocol']);
});
req.end();
- }
- );
- expect(protocol).toBe('vite-hmr');
+ });
+ for (const [host, expected] of [
+ [`${hostname}:${address.port}`, 'vite-hmr'],
+ // Tailscale Serve forwards the devbox's MagicDNS name as the Host.
+ ['devbox.example-tailnet.ts.net', 'vite-hmr'],
+ ['unrelated.example', 'HTTP 400'],
+ ]) {
+ expect(await upgradeHmr(host), host).toBe(expected);
+ }
} finally {
await vite.close();
}
diff --git a/apps/web/scripts/dev-https.ts b/apps/web/scripts/dev-https.ts
index 2c38f22c09..1572eef409 100644
--- a/apps/web/scripts/dev-https.ts
+++ b/apps/web/scripts/dev-https.ts
@@ -40,7 +40,9 @@ export function devHttps(
cert: readFileSync(join(directory, 'server.pem')),
key: readFileSync(join(directory, 'server-key.pem')),
},
- allowedHosts: [hostname],
+ // Tailscale Serve proxies a remote devbox over HTTP/2 under its
+ // MagicDNS name; Vite's HMR socket rejects hosts not listed here.
+ allowedHosts: [hostname, '.ts.net'],
},
};
} finally {