From 244823be7639adbd8a209a5941ccda5988553d93 Mon Sep 17 00:00:00 2001 From: alexpaynex <55271826-alexpaynex@users.noreply.replit.com> Date: Fri, 20 Mar 2026 01:09:00 +0000 Subject: [PATCH] Configure VM deployment and improve path resolution for frontend assets Update `artifact.toml` to set `deploymentTarget = "vm"` and refactor path resolution logic in `app.ts` for serving frontend assets, ensuring compatibility across different execution environments. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 90c7a60b-2c61-4699-b5c6-6a1ac7469a4d Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 7fd478cc-db13-47a8-8b57-14de9846c02a Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9f85e954-647c-46a5-90a7-396e495a805a/90c7a60b-2c61-4699-b5c6-6a1ac7469a4d/hoGhXo5 Replit-Helium-Checkpoint-Created: true --- .../api-server/.replit-artifact/artifact.toml | 1 + artifacts/api-server/src/app.ts | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) 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")));