Skip to content

Commit 2a23ce6

Browse files
authored
fix(server): avoid using browser-restricted port numbers (#1076)
1 parent 42de821 commit 2a23ce6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/utils/src/build/server.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@ import { execSync } from 'child_process';
66
import { Thirdparty } from '@rsdoctor/types';
77
import { random } from '../common/algorithm';
88

9-
export const defaultPort = random(3000, 8999);
9+
// see https://neo4j.com/developer/kb/list-of-restricted-ports-in-browsers
10+
const RESTRICTED_PORTS = [3659, 4045, 6000, 6665, 6666, 6667, 6668, 6669];
11+
12+
function getRandomPort(min: number, max: number) {
13+
let port: number;
14+
do {
15+
port = random(min, max);
16+
} while (RESTRICTED_PORTS.includes(port));
17+
return port;
18+
}
19+
20+
export const defaultPort = getRandomPort(3000, 8999);
1021

1122
export async function getPort(expectPort: number) {
1223
return gp({ port: expectPort });

0 commit comments

Comments
 (0)