From 058e6dfa2e4489e8b0f47d5a6628adf4ba3fb07f Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 26 Jun 2026 16:17:28 +0000 Subject: [PATCH 1/2] Disable WebSocket by default, gate behind ENABLE_WEBSOCKET flag Co-authored-by: Nane Hambardzumyan --- client/app.js | 9 ++++++++- server.js | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/client/app.js b/client/app.js index 0f924ce..e0a8b08 100644 --- a/client/app.js +++ b/client/app.js @@ -1,6 +1,11 @@ // app.js import Modal from './design-system/components/modal/modal.js'; +// WebSocket messaging is disabled by default. The API Simulator UI uses plain +// HTTP, so the optional alert/messaging channel is opt-in. Set this to true and +// run the server with ENABLE_WEBSOCKET=true to re-enable it. +const ENABLE_WEBSOCKET = false; + let websocket = null; let helpModal = null; let helpModalInitialized = false; @@ -114,7 +119,9 @@ async function initializeHelpModal() { // Initialize both help modal and WebSocket when DOM is ready async function initialize() { await initializeHelpModal(); - initializeWebSocket(); + if (ENABLE_WEBSOCKET) { + initializeWebSocket(); + } } if (document.readyState === 'loading') { diff --git a/server.js b/server.js index ea2aa91..2191cef 100644 --- a/server.js +++ b/server.js @@ -20,9 +20,13 @@ const fs = require('fs'); const fsp = fs.promises; const path = require('path'); const url = require('url'); -// Try to load WebSocket module, fallback if not available +// WebSocket support is opt-in. Set ENABLE_WEBSOCKET=true to enable the optional +// /ws channel and POST /message broadcasting. It is disabled by default because +// the API Simulator UI communicates over plain HTTP and does not use WebSockets. +const WEBSOCKET_ENABLED = process.env.ENABLE_WEBSOCKET === 'true'; let WebSocket = null; let isWebSocketAvailable = false; +if (WEBSOCKET_ENABLED) { try { WebSocket = require('ws'); isWebSocketAvailable = true; @@ -31,6 +35,9 @@ console.log('WebSocket support enabled'); console.log('WebSocket support disabled (ws package not installed)'); console.log('Install with: npm install ws'); } +} else { +console.log('WebSocket support disabled (set ENABLE_WEBSOCKET=true to enable)'); +} const DIST_DIR = path.join(__dirname, 'dist'); const DATA_DIR = path.join(__dirname, '.api-sim-data'); const EVENTS_FILE = path.join(DATA_DIR, 'events.jsonl'); From 40b3b952b327b9bdfb4995f8e316df94affa576b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 27 Jun 2026 07:20:25 +0000 Subject: [PATCH 2/2] Remove /ws Vite proxy to stop EPIPE errors when WebSocket is disabled Co-authored-by: Nane Hambardzumyan --- vite.config.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/vite.config.js b/vite.config.js index e317aaa..9086fa0 100644 --- a/vite.config.js +++ b/vite.config.js @@ -25,11 +25,6 @@ export default defineConfig({ '/message': { target: 'http://localhost:3001', changeOrigin: true - }, - '/ws': { - target: 'ws://localhost:3001', - ws: true, - changeOrigin: true } } },