diff --git a/artifacts/api-server/.replit-artifact/artifact.toml b/artifacts/api-server/.replit-artifact/artifact.toml index c3c7e43..c1d6896 100644 --- a/artifacts/api-server/.replit-artifact/artifact.toml +++ b/artifacts/api-server/.replit-artifact/artifact.toml @@ -3,6 +3,7 @@ previewPath = "/" title = "API Server" version = "1.0.0" id = "3B4_FFSkEVBkAeYMFRJ2e" +deploymentTarget = "vm" [[services]] localPort = 8080 diff --git a/artifacts/api-server/src/app.ts b/artifacts/api-server/src/app.ts index 4eec1c6..d415685 100644 --- a/artifacts/api-server/src/app.ts +++ b/artifacts/api-server/src/app.ts @@ -61,12 +61,23 @@ 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. -// 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"); +// +// Path resolution strategy: +// ESM dev (tsx ./src/index.ts): import.meta.url is a file:// URL; resolve 3 +// levels up from src/ to reach the workspace root. +// CJS prod bundle (node dist/index.cjs): import.meta is {} (empty), so fall +// back to process.cwd(). The run command is issued from the workspace root, +// so process.cwd() == workspace root. +const towerDist = (() => { + try { + const metaUrl: string | undefined = (import.meta as { url?: string }).url; + if (metaUrl && metaUrl.startsWith("file:")) { + return path.resolve(path.dirname(fileURLToPath(metaUrl)), "../../..", "the-matrix", "dist"); + } + } catch {} + // CJS bundle: run command is `node artifacts/api-server/dist/index.cjs` from workspace root + return path.join(process.cwd(), "the-matrix", "dist"); +})(); app.use("/tower", express.static(towerDist)); app.get("/tower/*splat", (_req, res) => res.sendFile(path.join(towerDist, "index.html")));