task(#44): Mobile app validation — fix Matrix URL and tower path CWD bug

## Original task
Validate and fix the Expo mobile app (Face/Matrix/Feed tabs) against the live API server.
Restart the API server (was EADDRINUSE from prior merge), verify domain config, test all three tabs, fix issues, and confirm TypeScript typecheck passes.

## Changes made

### artifacts/mobile/app/(tabs)/matrix.tsx
- Fixed getMatrixUrl(): was returning `https://{domain}/` (API landing page), now returns `https://{domain}/tower` (Three.js 3D world). This was the main UI bug — the Matrix tab was showing the wrong page.

### artifacts/api-server/src/app.ts
- Fixed tower static file path: replaced `path.resolve(process.cwd(), "the-matrix", "dist")` with `path.resolve(__dirname_app, "../../..", "the-matrix", "dist")` using `fileURLToPath(import.meta.url)`.
- Root cause: pnpm `--filter` runs scripts from the package directory (`artifacts/api-server`), so `process.cwd()` resolved to `artifacts/api-server/the-matrix/dist` (missing), not `the-matrix/dist` at workspace root. This caused /tower to 404 in development.
- The import.meta.url approach works correctly in both dev (tsx from src/) and production (esbuild CJS bundle from dist/) since both are 3 levels deep from workspace root.

### Infrastructure
- Killed stale process on port 18115, restarted Expo workflow (was stuck waiting for port with interactive prompt).
- Restarted API server (was EADDRINUSE from prior task merge).

## Verification
- API healthz returns 200, /tower/ returns 200.
- TypeScript typecheck passes for @workspace/mobile (no errors).
- TypeScript typecheck passes for @workspace/api-server (no errors).
- Expo dev server running on port 18115, Metro bundler active.
- WebSocket connections visible in API server logs (clients connected).
- EXPO_PUBLIC_DOMAIN set to $REPLIT_DEV_DOMAIN in dev script (correct for wss:// and https:// connections).
This commit is contained in:
alexpaynex
2026-03-20 00:48:24 +00:00
parent 2b70bdf362
commit f50d62332b
3 changed files with 10 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import express, { type Express } from "express";
import cors from "cors";
import path from "path";
import { fileURLToPath } from "url";
import router from "./routes/index.js";
import adminRelayPanelRouter from "./routes/admin-relay-panel.js";
import { responseTimeMiddleware } from "./middlewares/response-time.js";
@@ -58,8 +59,13 @@ app.use(adminRelayPanelRouter);
// ── Tower (Matrix 3D frontend) ───────────────────────────────────────────────
// Serve the pre-built Three.js world at /tower. WS client auto-connects to
// /api/ws on the same host. process.cwd() = workspace root at runtime.
const towerDist = path.resolve(process.cwd(), "the-matrix", "dist");
// /api/ws on the same host.
// Use import.meta.url so the path is correct whether the server is started from
// artifacts/api-server (dev) or the workspace root (production build).
// From src/ or dist/ (both 3 levels inside workspace), three "../" steps reach
// the workspace root where the-matrix/ lives.
const __dirname_app = path.dirname(fileURLToPath(import.meta.url));
const towerDist = path.resolve(__dirname_app, "../../..", "the-matrix", "dist");
app.use("/tower", express.static(towerDist));
app.get("/tower/*splat", (_req, res) => res.sendFile(path.join(towerDist, "index.html")));

View File

@@ -17,10 +17,10 @@ const C = Colors.dark;
function getMatrixUrl(): string {
const domain = process.env.EXPO_PUBLIC_DOMAIN ?? "";
if (!domain) return "http://localhost:8080/";
if (!domain) return "http://localhost:8080/tower";
const stripped = domain.replace(/^https?:\/\//, "").replace(/\/$/, "");
const proto = stripped.startsWith("localhost") ? "http" : "https";
return `${proto}://${stripped}/`;
return `${proto}://${stripped}/tower`;
}
export default function MatrixScreen() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 KiB