Explorar o código

Intervalle de recherche pour le port modifiable dans le fichier de config

Loquicom %!s(int64=5) %!d(string=hai) anos
pai
achega
21b2f08f17
Modificáronse 3 ficheiros con 13 adicións e 3 borrados
  1. 3 1
      node/config.json
  2. 2 2
      node/main.js
  3. 8 0
      node/src/config.js

+ 3 - 1
node/config.json

@@ -1,5 +1,7 @@
 {
   "storage": "database",
   "auth": true,
-  "findPort": true
+  "findPort": true,
+  "basePort": 8000,
+  "highestPort": 65535
 }

+ 2 - 2
node/main.js

@@ -69,8 +69,8 @@ portfinder.getPortPromise()
         if (err.toString().includes('Error: No open ports') && config.findPort) {
             console.info(`Port ${argv.port} not available, search for a new available port`);
             // Recherche d'un port ouvert
-            portfinder.basePort = 8000;
-            portfinder.highestPort = 65535;
+            portfinder.basePort = config.basePort;
+            portfinder.highestPort = config.highestPort;
             portfinder.getPortPromise()
                 .then((port) => {
                     app.listen(port, () => {

+ 8 - 0
node/src/config.js

@@ -19,6 +19,10 @@ if (config.storage === undefined) {
     throw 'Auth undefined in the config file';
 } else if (config.findPort === undefined) {
     throw 'findPort undefined in the config file';
+} else if (config.basePort === undefined) {
+    throw 'basePort undefined in the config file';
+} else if (config.highestPort === undefined) {
+    throw 'highestPort undefined in the config file';
 }
 
 //Verification valeur
@@ -28,6 +32,10 @@ if (config.storage !== 'database' && config.storage !== 'file') {
     throw 'Bad value for auth: boolean expected';
 } else if (typeof config.findPort !== 'boolean') {
     throw 'Bad value for findPort: boolean expected';
+} else if (config.basePort < 0 || config.basePort > 65535) {
+    throw 'Bad value for basePort: number between 0 and 65535 expected';
+} else if (config.highestPort < 0 || config.highestPort > 65535 || config.highestPort < config.basePort) {
+    throw 'Bad value for highestPort: number between 0 and 65535 and higher than or equal basePort expected';
 }
 
 module.exports = config;