[Haik]: ckpt, nine router now runs on different ports for dev vs prod. Also made a custom linter to enforce my standards

This commit is contained in:
haikdc
2026-03-30 08:53:52 -07:00
parent 7f3df20970
commit 6deebbd052
10 changed files with 418 additions and 9 deletions
+20 -6
View File
@@ -3,8 +3,9 @@
9Router is a free AI subscription proxy that lets users connect their
Claude/ChatGPT/Gemini subscriptions to OpenSwarm without API keys.
It runs silently in the background on port 20128 and exposes an
OpenAI-compatible API at localhost:20128/v1.
It runs silently in the background and exposes an OpenAI-compatible API
at localhost:<port>/v1. The port is read from ports.config.json (dev
vs prod) so the packaged app and the dev server never collide.
"""
import asyncio
@@ -115,7 +116,12 @@ async def ensure_running():
print(f"9Router: starting (production) on port {NINE_ROUTER_PORT}...", flush=True)
cmd = [node, standalone_server]
cwd = os.path.dirname(standalone_server)
env = {**os.environ, "PORT": str(NINE_ROUTER_PORT), "NODE_ENV": "production"}
env = {
**os.environ,
"PORT": str(NINE_ROUTER_PORT),
"NEXT_PUBLIC_BASE_URL": NINE_ROUTER_URL,
"NODE_ENV": "production",
}
if node == os.environ.get("OPENSWARM_ELECTRON_PATH"):
env["ELECTRON_RUN_AS_NODE"] = "1"
@@ -135,7 +141,11 @@ async def ensure_running():
print(f"9Router: starting (dev) on port {NINE_ROUTER_PORT}...", flush=True)
cmd = [npx, "next", "dev", "--webpack", "-p", str(NINE_ROUTER_PORT)]
cwd = _9router_dir
env = {**os.environ, "PORT": str(NINE_ROUTER_PORT)}
env = {
**os.environ,
"PORT": str(NINE_ROUTER_PORT),
"NEXT_PUBLIC_BASE_URL": NINE_ROUTER_URL,
}
else:
npx = shutil.which("npx")
@@ -143,9 +153,13 @@ async def ensure_running():
print("9Router: npx not found and no bundled 9router directory", flush=True)
return
print(f"9Router: starting (npx) on port {NINE_ROUTER_PORT}...", flush=True)
cmd = [npx, "9router"]
cmd = [npx, "9router", "--port", str(NINE_ROUTER_PORT)]
cwd = None
env = {**os.environ, "PORT": str(NINE_ROUTER_PORT)}
env = {
**os.environ,
"PORT": str(NINE_ROUTER_PORT),
"NEXT_PUBLIC_BASE_URL": NINE_ROUTER_URL,
}
try:
_process = subprocess.Popen(
+15 -1
View File
@@ -15,9 +15,23 @@ BACKEND_DEV_PORT: int = _cfg["backend"]["dev"]
BACKEND_PROD_PORT_START: int = _cfg["backend"]["prod"]["start"]
BACKEND_PROD_PORT_END: int = _cfg["backend"]["prod"]["end"]
FRONTEND_DEV_PORT: int = _cfg["frontend"]["dev"]
NINE_ROUTER_PORT: int = _cfg["nineRouter"]
NINE_ROUTER_DEV_PORT: int = _cfg["nineRouter"]["dev"]
NINE_ROUTER_PROD_PORT: int = _cfg["nineRouter"]["prod"]
def _is_packaged() -> bool:
return os.environ.get("OPENSWARM_PACKAGED") == "1"
def get_backend_port() -> int:
"""Return the active backend port (env override or dev default)."""
return int(os.environ.get("OPENSWARM_PORT", str(BACKEND_DEV_PORT)))
def get_nine_router_port() -> int:
"""Return the 9Router port for the current environment."""
return NINE_ROUTER_PROD_PORT if _is_packaged() else NINE_ROUTER_DEV_PORT
# Convenience alias — most callers just need the current port.
NINE_ROUTER_PORT: int = get_nine_router_port()
+3 -1
View File
@@ -8,4 +8,6 @@ pytest-asyncio==0.25.2
typeguard==4.4.2
Pillow
posthog
httpx>=0.27.0
httpx>=0.27.0
watchfiles
pyright