support configuring the port

This commit is contained in:
jinhui.li
2025-07-20 01:00:33 +08:00
parent 174c9a740f
commit d0de78eaf0
5 changed files with 10 additions and 8 deletions

View File

@@ -74,7 +74,7 @@ async function main() {
} }
break; break;
case "status": case "status":
showStatus(); await showStatus();
break; break;
case "code": case "code":
if (!isServiceRunning()) { if (!isServiceRunning()) {

View File

@@ -56,7 +56,7 @@ async function run(options: RunOptions = {}) {
); );
} }
const port = options.port || 3456; const port = config.PORT || 3456;
// Save the PID of the background process // Save the PID of the background process
savePid(process.pid); savePid(process.pid);

View File

@@ -12,7 +12,7 @@ export async function executeCodeCommand(args: string[] = []) {
const env = { const env = {
...process.env, ...process.env,
ANTHROPIC_AUTH_TOKEN: "test", ANTHROPIC_AUTH_TOKEN: "test",
ANTHROPIC_BASE_URL: `http://127.0.0.1:3456`, ANTHROPIC_BASE_URL: `http://127.0.0.1:${config.PORT || 3456}`,
API_TIMEOUT_MS: "600000", API_TIMEOUT_MS: "600000",
}; };

View File

@@ -1,5 +1,6 @@
import { existsSync, readFileSync, writeFileSync } from 'fs'; import { existsSync, readFileSync, writeFileSync } from 'fs';
import { PID_FILE, REFERENCE_COUNT_FILE } from '../constants'; import { PID_FILE, REFERENCE_COUNT_FILE } from '../constants';
import { readConfigFile } from '.';
export function incrementReferenceCount() { export function incrementReferenceCount() {
let count = 0; let count = 0;
@@ -70,15 +71,16 @@ export function getServicePid(): number | null {
} }
} }
export function getServiceInfo() { export async function getServiceInfo() {
const pid = getServicePid(); const pid = getServicePid();
const running = isServiceRunning(); const running = isServiceRunning();
const config = await readConfigFile();
return { return {
running, running,
pid, pid,
port: 3456, port: config.PORT,
endpoint: 'http://127.0.0.1:3456', endpoint: `http://127.0.0.1:${config.PORT}`,
pidFile: PID_FILE, pidFile: PID_FILE,
referenceCount: getReferenceCount() referenceCount: getReferenceCount()
}; };

View File

@@ -1,7 +1,7 @@
import { getServiceInfo } from './processCheck'; import { getServiceInfo } from './processCheck';
export function showStatus() { export async function showStatus() {
const info = getServiceInfo(); const info = await getServiceInfo();
console.log('\n📊 Claude Code Router Status'); console.log('\n📊 Claude Code Router Status');
console.log('═'.repeat(40)); console.log('═'.repeat(40));