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;
case "status":
showStatus();
await showStatus();
break;
case "code":
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
savePid(process.pid);

View File

@@ -12,7 +12,7 @@ export async function executeCodeCommand(args: string[] = []) {
const env = {
...process.env,
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",
};

View File

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

View File

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