mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 03:32:17 +08:00
fix find available port
This commit is contained in:
parent
dac2336eb6
commit
9f6aac708b
|
@ -24,7 +24,6 @@ function FindProxyForURL(url, host) {
|
|||
export function findAvailablePort(startPort: number): Promise<number> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const server = net.createServer()
|
||||
server.unref()
|
||||
server.on('error', (err) => {
|
||||
if (startPort <= 65535) {
|
||||
resolve(findAvailablePort(startPort + 1))
|
||||
|
@ -32,13 +31,12 @@ export function findAvailablePort(startPort: number): Promise<number> {
|
|||
reject(err)
|
||||
}
|
||||
})
|
||||
|
||||
server.listen(startPort, () => {
|
||||
// 端口可用
|
||||
server.on('listening', () => {
|
||||
server.close(() => {
|
||||
resolve(startPort)
|
||||
})
|
||||
})
|
||||
server.listen(startPort, '127.0.0.1')
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user