@@ -6,15 +6,14 @@ import { Context } from '../types.js'
66import { Logger } from 'winston'
77import { validateSnapshot } from './schemaValidation.js'
88import { pingIntervalId , startPollingForTunnel , stopTunnelHelper , isTunnelPolling } from './utils.js' ;
9+ import constants from './constants.js' ;
910var fp = require ( "find-free-port" )
1011
1112const uploadDomToS3ViaEnv = process . env . USE_LAMBDA_INTERNAL || false ;
1213
1314// Helper function to find an available port
1415async function findAvailablePort ( server : FastifyInstance , startPort : number , log : Logger ) : Promise < number > {
1516 let currentPort = startPort ;
16- let attempts = 0 ;
17- let maxAttempts = 10 ;
1817
1918 // If the default port gives error, use find-free-port with range 49100-60000
2019 try {
@@ -25,7 +24,7 @@ async function findAvailablePort(server: FastifyInstance, startPort: number, log
2524 log . debug ( `Port ${ currentPort } is in use, finding available port in range 49100-60000` ) ;
2625
2726 // Use find-free-port to get an available port in the specified range
28- const availablePorts = await fp ( 49100 , 60000 ) ;
27+ const availablePorts = await fp ( constants . MIN_PORT_RANGE , constants . MAX_PORT_RANGE ) ;
2928 if ( availablePorts . length > 0 ) {
3029 const freePort = availablePorts [ 0 ] ;
3130 await server . listen ( { port : freePort } ) ;
0 commit comments