fix: use process.cwd() for tower path — import.meta.url is undefined in CJS bundle
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
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 { responseTimeMiddleware } from "./middlewares/response-time.js";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const app: Express = express();
|
||||
|
||||
app.set("trust proxy", 1);
|
||||
@@ -50,11 +47,9 @@ app.use(responseTimeMiddleware);
|
||||
app.use("/api", router);
|
||||
|
||||
// ── Tower (Matrix 3D frontend) ───────────────────────────────────────────────
|
||||
// Serve the pre-built Three.js world at /tower. The Matrix's WebSocket client
|
||||
// auto-connects to /api/ws on the same host.
|
||||
// __dirname resolves to artifacts/api-server/dist/ at runtime.
|
||||
// Go up three levels to reach workspace root, then into the-matrix/dist.
|
||||
const towerDist = path.join(__dirname, "..", "..", "..", "the-matrix", "dist");
|
||||
// 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");
|
||||
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