mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-13 15:35:17 +00:00
chore: automate git worktree setup (shared node_modules, per-worktree dev port)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { createServer } from "node:net";
|
||||
|
||||
function isFree(port) {
|
||||
return new Promise((resolve) => {
|
||||
const server = createServer();
|
||||
server.once("error", () => resolve(false));
|
||||
server.listen(port, "0.0.0.0", () => {
|
||||
server.close(() => resolve(true));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function findFreePort(start) {
|
||||
let port = start;
|
||||
while (!(await isFree(port))) {
|
||||
port++;
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
const start = Number.parseInt(process.argv[2] || process.env.PORT || "3000", 10);
|
||||
const port = await findFreePort(start);
|
||||
process.stdout.write(String(port));
|
||||
Reference in New Issue
Block a user