Merge branch 'HeyPuter:main' into shuguet/add-github-action-build-docker-image

This commit is contained in:
Sylvain Huguet 2024-03-15 10:43:44 +01:00 committed by GitHub
commit baebf2f551
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,15 +10,14 @@ let port = process.env.PORT ?? 4000; // Starting port
const maxAttempts = 10; // Maximum number of ports to try const maxAttempts = 10; // Maximum number of ports to try
const env = argv[2] ?? "dev"; const env = argv[2] ?? "dev";
const startServer = (attempt) => { const startServer = (attempt, useAnyFreePort = false) => {
if (attempt > maxAttempts) { if (attempt > maxAttempts) {
console.error(chalk.red(`ERROR: Unable to find an available port after ${maxAttempts} attempts.`)); useAnyFreePort = true; // Use any port that is free
return;
} }
app.listen(port, () => { const server = app.listen(useAnyFreePort ? 0 : port, () => {
console.log("\n-----------------------------------------------------------\n"); console.log("\n-----------------------------------------------------------\n");
console.log(`Puter is now live at: `, chalk.underline.blue(`http://localhost:${port}`)); console.log(`Puter is now live at: `, chalk.underline.blue(`http://localhost:${server.address().port}`));
console.log("\n-----------------------------------------------------------\n"); console.log("\n-----------------------------------------------------------\n");
}).on('error', (err) => { }).on('error', (err) => {
if (err.code === 'EADDRINUSE') { // Check if the error is because the port is already in use if (err.code === 'EADDRINUSE') { // Check if the error is because the port is already in use