From 8caf5d622eb134f1630cc7223aafebeccb93340c Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Fri, 23 Apr 2021 20:49:52 +0200 Subject: [PATCH] using random free port for electron app #91 #86 --- packages/api/package.json | 4 ++-- packages/api/src/main.js | 6 +++--- yarn.lock | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/api/package.json b/packages/api/package.json index f0e0868e..3879b8e6 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -31,8 +31,8 @@ "express": "^4.17.1", "express-basic-auth": "^1.2.0", "express-fileupload": "^1.2.0", - "find-free-port": "^2.0.0", "fs-extra": "^9.1.0", + "get-port": "^5.1.1", "http": "^0.0.0", "json-stable-stringify": "^1.0.1", "line-reader": "^0.4.0", @@ -68,4 +68,4 @@ "optionalDependencies": { "msnodesqlv8": "^2.0.10" } -} \ No newline at end of file +} diff --git a/packages/api/src/main.js b/packages/api/src/main.js index e63dfbba..fff13c5e 100644 --- a/packages/api/src/main.js +++ b/packages/api/src/main.js @@ -6,7 +6,7 @@ const http = require('http'); const cors = require('cors'); const io = require('socket.io'); const fs = require('fs'); -const findFreePort = require('find-free-port'); +const getPort = require('get-port'); const childProcessChecker = require('./utility/childProcessChecker'); const path = require('path'); const crypto = require('crypto'); @@ -107,7 +107,7 @@ function start() { authorization = crypto.randomBytes(32).toString('hex'); - findFreePort(53911, function (err, port) { + getPort().then(port => { server.listen(port, () => { console.log(`DbGate API listening on port ${port}`); process.send({ msgtype: 'listening', port, authorization }); @@ -115,7 +115,7 @@ function start() { }); } else if (platformInfo.isNpmDist) { app.use(express.static(path.join(__dirname, '../../dbgate-web/public'))); - findFreePort(5000, function (err, port) { + getPort({ port: 5000 }).then(port => { server.listen(port, () => { console.log(`DbGate API listening on port ${port}`); }); diff --git a/yarn.lock b/yarn.lock index 57b73a7b..41aeb66b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3425,11 +3425,6 @@ find-cache-dir@^2.1.0: make-dir "^2.0.0" pkg-dir "^3.0.0" -find-free-port@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/find-free-port/-/find-free-port-2.0.0.tgz#4b22e5f6579eb1a38c41ac6bcb3efed1b6da9b1b" - integrity sha1-SyLl9leesaOMQaxryz7+0bbamxs= - find-up@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73" @@ -3687,6 +3682,11 @@ get-port@^3.2.0: resolved "https://registry.yarnpkg.com/get-port/-/get-port-3.2.0.tgz#dd7ce7de187c06c8bf353796ac71e099f0980ebc" integrity sha1-3Xzn3hh8Bsi/NTeWrHHgmfCYDrw= +get-port@^5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/get-port/-/get-port-5.1.1.tgz#0469ed07563479de6efb986baf053dcd7d4e3193" + integrity sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ== + get-stream@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14"