diff --git a/nodecar/src/index.ts b/nodecar/src/index.ts index 1b01162..327bb53 100644 --- a/nodecar/src/index.ts +++ b/nodecar/src/index.ts @@ -23,58 +23,68 @@ program .option("--ignore-certificate", "ignore certificate errors for HTTPS proxies") .option("--id ", "proxy ID for stop command") .description("manage proxy servers") - .action(async (action, options) => { - if (action === "start") { - if (!options.upstream) { - console.error("Error: Upstream proxy URL is required"); - console.log( - "Example: proxy start -u http://username:password@proxy.example.com:8080" - ); - return; + .action( + async ( + action: string, + options: { + upstream?: string; + port?: number; + ignoreCertificate?: boolean; + id?: string; } - - try { - const config = await startProxyProcess(options.upstream, { - port: options.port, - ignoreProxyCertificate: options.ignoreCertificate, - }); - console.log(JSON.stringify(config)); - } catch (error: any) { - console.error(`Failed to start proxy: ${error.message}`); - } - } else if (action === "stop") { - if (options.id) { - const stopped = await stopProxyProcess(options.id); - console.log(`{ - "success": ${stopped}}`); - } else if (options.upstream) { - // Find proxies with this upstream URL - const configs = listProxyConfigs().filter( - (config) => config.upstreamUrl === options.upstream - ); - - if (configs.length === 0) { - console.error(`No proxies found for ${options.upstream}`); + ) => { + if (action === "start") { + if (!options.upstream) { + console.error("Error: Upstream proxy URL is required"); + console.log( + "Example: proxy start -u http://username:password@proxy.example.com:8080" + ); return; } - for (const config of configs) { - const stopped = await stopProxyProcess(config.id); + try { + const config = await startProxyProcess(options.upstream, { + port: options.port, + ignoreProxyCertificate: options.ignoreCertificate, + }); + console.log(JSON.stringify(config)); + } catch (error: any) { + console.error(`Failed to start proxy: ${error.message}`); + } + } else if (action === "stop") { + if (options.id) { + const stopped = await stopProxyProcess(options.id); console.log(`{ "success": ${stopped}}`); - } - } else { - await stopAllProxyProcesses(); - console.log(`{ + } else if (options.upstream) { + // Find proxies with this upstream URL + const configs = listProxyConfigs().filter( + (config) => config.upstreamUrl === options.upstream + ); + + if (configs.length === 0) { + console.error(`No proxies found for ${options.upstream}`); + return; + } + + for (const config of configs) { + const stopped = await stopProxyProcess(config.id); + console.log(`{ + "success": ${stopped}}`); + } + } else { + await stopAllProxyProcesses(); + console.log(`{ "success": true}`); + } + } else if (action === "list") { + const configs = listProxyConfigs(); + console.log(JSON.stringify(configs)); + } else { + console.error("Invalid action. Use 'start', 'stop', or 'list'"); } - } else if (action === "list") { - const configs = listProxyConfigs(); - console.log(JSON.stringify(configs)); - } else { - console.error("Invalid action. Use 'start', 'stop', or 'list'"); } - }); + ); // Command for proxy worker (internal use) program @@ -82,7 +92,7 @@ program .argument("", "start a proxy worker") .requiredOption("--id ", "proxy configuration ID") .description("run a proxy worker process") - .action(async (action, options) => { + .action(async (action: string, options: { id: string }) => { if (action === "start") { await runProxyWorker(options.id); } else { diff --git a/tsconfig.json b/tsconfig.json index 19e161f..33b4b10 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -31,5 +31,5 @@ "next-env.d.ts", "dist/types/**/*.ts" ], - "exclude": ["node_modules"] + "exclude": ["node_modules", "nodecar"] }