mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-09-23 07:25:16 +00:00
Add support for random port assignment
This commit is contained in:
@@ -112,6 +112,7 @@ if (manifestJsonFile.singleInstance || manifestJsonFile.aspCoreBackendPort) {
|
||||
|
||||
if (!mainInstance) {
|
||||
app.quit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +140,9 @@ app.on('ready', () => {
|
||||
let defaultElectronPort = 8000;
|
||||
if (manifestJsonFile.electronPort) {
|
||||
defaultElectronPort = (manifestJsonFile.electronPort)
|
||||
if (defaultElectronPort == 'random') {
|
||||
defaultElectronPort = Math.floor(Math.random() * 2000 + 8000); //Use random port to reduce risk of race conditions between when we find a free port here, and when the app locks on the port
|
||||
}
|
||||
}
|
||||
// hostname needs to be localhost, otherwise Windows Firewall will be triggered.
|
||||
portscanner.findAPortNotInUse(defaultElectronPort, 65535, 'localhost', function (error, port) {
|
||||
|
||||
Reference in New Issue
Block a user