File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -197,8 +197,25 @@ program.command("start <name>")
197197 const command = process . argv . slice ( idx + 1 ) . join ( " " ) ;
198198 const apps = await loadApps ( ) ;
199199
200- // Use custom ports if provided via env, otherwise allocate dynamically
201- const httpPort = Number ( process . env . PORT || await getFreePort ( ) ) ;
200+ // Try to detect explicit port in command
201+ let detectedPort = null ;
202+
203+ // Matches:
204+ // 127.0.0.1:8000
205+ // :8000
206+ // http.server 8000
207+ const match =
208+ command . match ( / 1 2 7 \. 0 \. 0 \. 1 : ( \d + ) / ) ||
209+ command . match ( / : ( \d { 2 , 5 } ) / ) ||
210+ command . match ( / \s ( \d { 2 , 5 } ) ( \s | $ ) / ) ;
211+
212+ if ( match ) {
213+ detectedPort = Number ( match [ 1 ] ) ;
214+ }
215+
216+ const httpPort =
217+ detectedPort ||
218+ ( process . env . PORT ? Number ( process . env . PORT ) : await getFreePort ( ) ) ;
202219 const sslPort = process . env . SSL_PORT ? Number ( process . env . SSL_PORT ) : null ;
203220
204221 const ports = [ { virtual : 80 , target : httpPort } ] ;
You can’t perform that action at this time.
0 commit comments