@@ -40,39 +40,46 @@ async function main() {
4040 }
4141
4242 let providerLabel = 'unknown' ;
43+ let resolvedTargetUrl = targetUrl ;
44+ let parsedTarget ;
4345 try {
44- const parsedTarget = new URL ( targetUrl ) ;
45- providerLabel = parsedTarget . hostname || parsedTarget . host || 'unknown' ;
46+ parsedTarget = new URL ( targetUrl ) ;
4647 } catch {
4748 throw new Error ( 'TARGET_URL must be a valid URL (e.g. https://api.openai.com)' ) ;
4849 }
4950
51+ if ( process . env . TARGET_PORT ) {
52+ const targetPort = parseInt ( process . env . TARGET_PORT , 10 ) ;
53+ if ( ! Number . isFinite ( targetPort ) || targetPort <= 0 || targetPort > 65535 ) {
54+ throw new Error ( 'TARGET_PORT must be a valid TCP port (1-65535)' ) ;
55+ }
56+ parsedTarget . port = String ( targetPort ) ;
57+ resolvedTargetUrl = parsedTarget . toString ( ) ;
58+ }
59+
60+ providerLabel = parsedTarget . hostname || parsedTarget . host || 'unknown' ;
61+
5062 const config = {
5163 host : proxyHost ,
5264 port : portNumber ,
5365 outputDir : getLogsDir ( ) ,
54- targetUrl,
66+ targetUrl : resolvedTargetUrl ,
5567 provider : providerLabel ,
5668 } ;
5769
5870 intro ( 'llm-debugger' ) ;
59- log . info ( `Target: ${ targetUrl } ` ) ;
71+ log . info ( `Target: ${ resolvedTargetUrl } ` ) ;
6072
6173 const endpointSummary = [
62- `Proxy URL: http://${ proxyHost } :${ proxyPort } ` ,
63- `Proxy Route: http://${ proxyHost } :${ proxyPort } /proxy/*` ,
64- `Viewer: http://${ proxyHost } :${ proxyPort } /viewer` ,
65- `Logs: ${ config . outputDir } ` ,
66- `Client Base: http://${ proxyHost } :${ proxyPort } ` ,
67- `Target Host: ${ providerLabel } ` ,
74+ `Proxy: http://${ proxyHost } :${ proxyPort } /* to ${ resolvedTargetUrl } ` ,
6875 ] . join ( '\n' ) ;
6976
7077 const startSpinner = spinner ( ) ;
7178 startSpinner . start ( 'Starting server' ) ;
7279
7380 createServer ( config , {
7481 onListen : ( ) => {
75- startSpinner . stop ( `Server listening on ${ proxyHost } :${ proxyPort } ` ) ;
82+ startSpinner . stop ( `Server listening on http:// ${ proxyHost } :${ proxyPort } /viewer ` ) ;
7683 note ( endpointSummary , 'Endpoints' ) ;
7784 } ,
7885 } ) ;
@@ -88,6 +95,7 @@ Options:
8895 --proxy-host <host> Proxy host (default: localhost)
8996 --proxy-port <port> Proxy port (default: 8000)
9097 --target <url> Base target URL for proxying (required)
98+ --target-port <port> Override target URL port
9199 --home <dir> Base directory for config/logs
92100 --config <path> Path to config.yaml
93101 --logs <dir> Log output directory
@@ -139,6 +147,7 @@ function applyCliEnv(flags) {
139147 if ( flags [ 'proxy-host' ] ) process . env . PROXY_HOST = String ( flags [ 'proxy-host' ] ) ;
140148 if ( flags [ 'proxy-port' ] ) process . env . PROXY_PORT = String ( flags [ 'proxy-port' ] ) ;
141149 if ( flags . target ) process . env . TARGET_URL = String ( flags . target ) ;
150+ if ( flags [ 'target-port' ] ) process . env . TARGET_PORT = String ( flags [ 'target-port' ] ) ;
142151}
143152
144153function runInit ( force ) {
0 commit comments