Files
OmniRoute/src/lib/runtime/ports.ts
Steven Rafferty d0138a5037 feat: enhance port configuration and API bridge support
- Updated .env.example to include optional split ports for API and dashboard.
- Modified docker-compose files to dynamically use the configured ports.
- Introduced a new script (run-standalone.mjs) for running the server with environment-specific ports.
- Implemented an API bridge server to handle OpenAI-compatible routes when using split ports.
- Updated README and CLI tool documentation to reflect changes in port usage and configuration.
- Enhanced various components to utilize the new port configuration, ensuring backward compatibility.
2026-02-26 15:11:40 +00:00

33 lines
1.0 KiB
TypeScript

const DEFAULT_PORT = 20128;
function parsePort(value: string | undefined, fallback: number): number {
if (!value) return fallback;
const parsed = Number.parseInt(String(value), 10);
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535) return fallback;
return parsed;
}
export type RuntimePorts = {
port: number;
apiPort: number;
dashboardPort: number;
apiPortExplicit: boolean;
dashboardPortExplicit: boolean;
};
export function getRuntimePorts(): RuntimePorts {
// OMNIROUTE_PORT preserves the user's canonical PORT in wrapped runtimes
// where Next.js requires process.env.PORT to be the dashboard listener port.
const basePort = parsePort(process.env.OMNIROUTE_PORT || process.env.PORT, DEFAULT_PORT);
const apiPortExplicit = !!process.env.API_PORT;
const dashboardPortExplicit = !!process.env.DASHBOARD_PORT;
return {
port: basePort,
apiPort: parsePort(process.env.API_PORT, basePort),
dashboardPort: parsePort(process.env.DASHBOARD_PORT, basePort),
apiPortExplicit,
dashboardPortExplicit,
};
}