Skip to content

Commit

Permalink
Add portfinder
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlee85 committed Dec 16, 2024
1 parent 0922c4a commit a0bd7bb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
11 changes: 9 additions & 2 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'node:path';
import assert from 'node:assert';
import express from 'express';
import proxy from 'express-http-proxy';
import { getPortPromise as getPort } from 'portfinder';

/**
* Patch `logger` methods to include prefix
Expand Down Expand Up @@ -263,8 +264,14 @@ export function start(options = {}) {
});
});

// Start the Express server
const port = config.port;
// Start the Express server on the available port
const startPort = config.port;
const port = await getPort({ startPort, stopPort: startPort + 5 });

if (port !== startPort) {
logger.warn(`Port ${startPort} is already in use. Using port ${port} instead.`);
}

app.listen(port, () => {
logger.info(`Express.js server is running on port ${port}`);
});
Expand Down
61 changes: 60 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
},
"dependencies": {
"express": "^4.21.2",
"express-http-proxy": "^2.1.1"
"express-http-proxy": "^2.1.1",
"portfinder": "^1.0.32"
},
"devDependencies": {
"@harperdb/code-guidelines": "^0.0.2",
Expand Down

0 comments on commit a0bd7bb

Please sign in to comment.