Skip to content

Commit 994dd84

Browse files
author
Victoria Hall
committed
port variables
1 parent 90a953e commit 994dd84

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/http/httpProxy.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { HttpResponse } from './HttpResponse';
1212

1313
const requests: Record<string, http.IncomingMessage> = {};
1414
const responses: Record<string, http.ServerResponse> = {};
15+
const minPort = 55000;
16+
const maxPort = 65535;
1517

1618
const invocRequestEmitter = new EventEmitter();
1719

@@ -111,7 +113,7 @@ export async function setupHttpProxy(): Promise<string> {
111113
if (address.port === 0) {
112114
// Auto-assigned port is 0, find and bind to an open port
113115
workerSystemLog('debug', `Port 0 assigned. Finding open port.`);
114-
findOpenPort(51929, (openPort: number) => {
116+
findOpenPort((openPort: number) => {
115117
// Close the server and re-listen on the found open port
116118
server.close();
117119
server.listen(openPort, () => {
@@ -136,12 +138,12 @@ export async function setupHttpProxy(): Promise<string> {
136138
}
137139

138140
// Function to get a random port within a specified range
139-
function getRandomPort(minPort = 55000, maxPort = 65535): number {
141+
function getRandomPort(): number {
140142
return Math.floor(Math.random() * (maxPort - minPort + 1)) + minPort;
141143
}
142144

143145
// Function to find an open port starting from a specified port
144-
function findOpenPort(startingPort: number, callback: (port: number) => void): void {
146+
function findOpenPort(callback: (port: number) => void): void {
145147
const server = net.createServer();
146148

147149
function tryPort(port: number) {
@@ -166,5 +168,5 @@ function findOpenPort(startingPort: number, callback: (port: number) => void): v
166168
}
167169

168170
// Start trying from the specified starting port
169-
tryPort(startingPort);
171+
tryPort(minPort);
170172
}

0 commit comments

Comments
 (0)