From 132b36705301c7361351ab5e23d289b783414149 Mon Sep 17 00:00:00 2001 From: Jeremy Scheff Date: Mon, 2 Dec 2024 22:47:19 -0500 Subject: [PATCH] Use port 3000 by default, and fall back to some other arbitrary port if 3000 is already in use. Fixes #470 --- README.md | 3 ++- package.json | 1 + pnpm-lock.yaml | 9 +++++++++ tools/server.js | 3 ++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 583825531e..e961497190 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,8 @@ Run pnpm run start -and point your browser to . If you use the command `pnpm +and point your browser to (or it will use a different +port if 3000 is already used by somethign else). If you use the command `pnpm run start-watch` from above, then running the command `pnpm run start` is not necessary. diff --git a/package.json b/package.json index 778ff01073..c00c77e333 100644 --- a/package.json +++ b/package.json @@ -137,6 +137,7 @@ "eslint-plugin-react-hooks": "^5.0.0", "fake-indexeddb": "^6.0.0", "fs-extra": "^11.2.0", + "get-port": "^7.1.0", "globals": "^15.13.0", "html-minifier-terser": "^7.2.0", "husky": "^9.1.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9be8bdd68a..04e37bb509 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -321,6 +321,9 @@ importers: fs-extra: specifier: ^11.2.0 version: 11.2.0 + get-port: + specifier: ^7.1.0 + version: 7.1.0 globals: specifier: ^15.13.0 version: 15.13.0 @@ -3251,6 +3254,10 @@ packages: resolution: {integrity: sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==} engines: {node: '>=8.0.0'} + get-port@7.1.0: + resolution: {integrity: sha512-QB9NKEeDg3xxVwCCwJQ9+xycaz6pBB6iQ76wiWMl1927n0Kir6alPiP+yuiICLLU4jpMe08dXfpebuQppFA2zw==} + engines: {node: '>=16'} + get-stream@6.0.1: resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} engines: {node: '>=10'} @@ -8964,6 +8971,8 @@ snapshots: get-package-type@0.1.0: {} + get-port@7.1.0: {} + get-stream@6.0.1: {} get-stream@8.0.1: {} diff --git a/tools/server.js b/tools/server.js index 085f61256c..4ea8e86b64 100644 --- a/tools/server.js +++ b/tools/server.js @@ -2,8 +2,9 @@ import fs from "node:fs"; import http from "node:http"; import path from "node:path"; import os from "node:os"; +import getPort from "get-port"; -const port = 3006; +const port = await getPort({ port: 3000 }); const mimeTypes = { ".bmp": "image/bmp",