Skip to content

Commit 797104f

Browse files
committed
More PR review changes
1 parent fcde6cb commit 797104f

File tree

2 files changed

+19
-48
lines changed

2 files changed

+19
-48
lines changed

templates/cli/lib/commands/run.js.twig

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,28 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
4949
const taken = await isPortTaken(port);
5050

5151
if(taken) {
52-
log(`Port ${port} is already in use by another process.`);
53-
port = null;
52+
error(`Port ${port} is already in use by another process.`);
53+
return;
5454
}
5555
}
5656

5757
if(!port) {
58-
const answers = await inquirer.prompt(questionsRunFunctions[1]);
59-
port = answers.port;
58+
let portFound = fale;
59+
port = 3000;
60+
while(port < 3100) {
61+
const taken = await isPortTaken(port);
62+
if(!taken) {
63+
portFound = true;
64+
break;
65+
}
66+
67+
port++;
68+
}
69+
70+
if(!portFound) {
71+
error('Could not auto-suggest an available port. Please configure port with `appwrite run --port YOUR_PORT` command.');
72+
return;
73+
}
6074
}
6175

6276
// Configuration: Engine

templates/cli/lib/questions.js.twig

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -791,50 +791,7 @@ const questionsRunFunctions = [
791791
})
792792
return choices;
793793
}
794-
},
795-
{
796-
type: "input",
797-
name: "port",
798-
message: 'Which port would you like function to listen on?',
799-
default: async () => {
800-
let port = 3000;
801-
while(port < 3100) {
802-
const taken = await isPortTaken(port);
803-
if(!taken) {
804-
return port;
805-
}
806-
807-
port++;
808-
}
809-
810-
return 3000;
811-
},
812-
validate: function(value) {
813-
const done = this.async();
814-
815-
(async () => {
816-
if (typeof value !== 'number' && isNaN(+value)) {
817-
throw Error(`Port needs to be a valid integer between 1024 and 65536.`);
818-
}
819-
820-
value = +value;
821-
822-
if(value < 1024 || value > 65536) {
823-
throw Error(`Port needs to be a valid integer between 1024 and 65536.`);
824-
}
825-
826-
const taken = await isPortTaken(value);
827-
828-
if(taken) {
829-
throw Error(`Port ${value} is in use by another process. Pick a different one.`);
830-
}
831-
})().then(() => {
832-
done(null, true);
833-
}).catch((err) => {
834-
done(err.message);
835-
});
836-
},
837-
},
794+
}
838795
];
839796

840797
module.exports = {

0 commit comments

Comments
 (0)