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
This commit is contained in:
@@ -3,6 +3,7 @@ previewPath = "/"
|
||||
title = "API Server"
|
||||
version = "1.0.0"
|
||||
id = "3B4_FFSkEVBkAeYMFRJ2e"
|
||||
deploymentTarget = "vm"
|
||||
|
||||
[[services]]
|
||||
localPort = 8080
|
||||
|
||||
@@ -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")));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user