Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.2 KB
Raw Blame
/**
 * resolveServerEntry.js — pure helper for selecting the Next.js server entrypoint.
 *
 * The WS-aware wrapper `server-ws.mjs` installs the trusted peer-IP stamp
 * (peer-stamp.mjs) that the authz middleware needs to allow loopback/LAN access
 * to LOCAL_ONLY routes (AgentBridge, MCP, services, etc.).  Without it every
 * LOCAL_ONLY request returns 403.
 *
 * We prefer `server-ws.mjs` when it exists — mirroring run-standalone.mjs — and
 * fall back to the bare `server.js` only when the wrapper is absent (e.g. an
 * older build or a stripped bundle).
 *
 * Extracted as a pure helper so it can be unit-tested without importing the full
 * Electron main process (which requires the Electron binary).
 *
 * @param {string}   serverDir   - directory that contains server.js / server-ws.mjs
 * @param {Function} existsSyncFn - injectable fs.existsSync (for unit tests)
 * @returns {string} filename ("server-ws.mjs" or "server.js")
 */
function resolveServerEntry(serverDir, existsSyncFn) {
  const path = require("path");
  const wsEntry = path.join(serverDir, "server-ws.mjs");
  return existsSyncFn(wsEntry) ? "server-ws.mjs" : "server.js";
}

module.exports = { resolveServerEntry };