Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/cli/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IpcMain } from "@/node/services/ipcMain";
import { migrateCmuxToMux } from "@/common/constants/paths";
import cors from "cors";
import type { BrowserWindow, IpcMain as ElectronIpcMain } from "electron";
import { existsSync } from "fs";
import express from "express";
import * as http from "http";
import * as path from "path";
Expand Down Expand Up @@ -140,6 +141,14 @@ app.use(express.json({ limit: "50mb" }));
const clients: Clients = new Map();

const mockWindow = new MockBrowserWindow(clients);
const STATIC_ROOT = path.resolve(__dirname, "..");
const STATIC_INDEX = path.join(STATIC_ROOT, "index.html");

if (!existsSync(STATIC_INDEX)) {
console.warn(
`[mux-server] Built renderer missing at ${STATIC_INDEX}. Did you run "make build-renderer"?`
);
}
const httpIpcMain = new HttpIpcMainAdapter(app);

// Initialize async services and register handlers
Expand Down Expand Up @@ -176,7 +185,7 @@ const httpIpcMain = new HttpIpcMainAdapter(app);
});

// Serve static files from dist directory (built renderer)
app.use(express.static(path.join(__dirname, ".")));
app.use(express.static(STATIC_ROOT));

// Health check endpoint
app.get("/health", (req, res) => {
Expand All @@ -186,7 +195,7 @@ const httpIpcMain = new HttpIpcMainAdapter(app);
// Fallback to index.html for SPA routes (use middleware instead of deprecated wildcard)
app.use((req, res, next) => {
if (!req.path.startsWith("/ipc") && !req.path.startsWith("/ws")) {
res.sendFile(path.join(__dirname, "index.html"));
res.sendFile(path.join(STATIC_ROOT, "index.html"));
} else {
next();
}
Expand Down
Loading