From 36f9c76fa91a6bf02e7bc9f4a12404bdecb9a036 Mon Sep 17 00:00:00 2001 From: syntaxbullet Date: Sun, 8 Feb 2026 16:41:47 +0100 Subject: [PATCH] refactor(web): convert server to API-only mode - Remove build process spawning for frontend bundler - Remove SPA fallback and static file serving - Return 404 for unknown routes instead of serving index.html - Keep all REST API endpoints and WebSocket functionality --- web/src/server.ts | 86 ++++------------------------------------------- 1 file changed, 7 insertions(+), 79 deletions(-) diff --git a/web/src/server.ts b/web/src/server.ts index 036af63..986d681 100644 --- a/web/src/server.ts +++ b/web/src/server.ts @@ -1,10 +1,10 @@ /** - * Web server factory module. - * Exports a function to create and start the web server. + * API server factory module. + * Exports a function to create and start the API server. * This allows the server to be started in-process from the main application. */ -import { serve, spawn, type Subprocess } from "bun"; +import { serve } from "bun"; import { join, resolve, dirname } from "path"; import { logger } from "@shared/lib/logger"; @@ -20,37 +20,13 @@ export interface WebServerInstance { } /** - * Creates and starts the web server. - * - * Automatically handles building the frontend: - * - In development: Spawns 'bun run build.ts --watch' - * - In production: Assumes 'dist' is already built (or builds once) + * Creates and starts the API server. */ export async function createWebServer(config: WebServerConfig = {}): Promise { const { port = 3000, hostname = "localhost" } = config; - // Resolve directories - // server.ts is in web/src/, so we go up one level to get web/ + // Resolve directories for asset serving const currentDir = dirname(new URL(import.meta.url).pathname); - const webRoot = resolve(currentDir, ".."); - const distDir = join(webRoot, "dist"); - - // Manage build process in development - let buildProcess: Subprocess | undefined; - const isDev = process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "test"; - - if (isDev) { - logger.info("web", "Starting Web Bundler in Watch Mode..."); - try { - buildProcess = spawn(["bun", "run", "build.ts", "--watch"], { - cwd: webRoot, - stdout: "inherit", - stderr: "inherit", - }); - } catch (error) { - logger.error("web", "Failed to start build process", error); - } - } // Configuration constants const MAX_CONNECTIONS = 10; @@ -737,52 +713,8 @@ export async function createWebServer(config: WebServerConfig = {}): Promise

🛠️ Dashboard is building...

Please refresh in a few seconds. The bundler is currently generating the static assets.

", { - status: 503, - headers: { "Content-Type": "text/html" } - }); - } - return new Response("Dashboard Not Found", { status: 404 }); - } - - const indexHtml = await indexFile.text(); - return new Response(indexHtml, { headers: { "Content-Type": "text/html" } }); + // No frontend - return 404 for unknown routes + return new Response("Not Found", { status: 404 }); }, websocket: { @@ -847,7 +779,6 @@ export async function createWebServer(config: WebServerConfig = {}): Promise { - if (buildProcess) { - buildProcess.kill(); - } if (statsBroadcastInterval) { clearInterval(statsBroadcastInterval); }