summaryrefslogtreecommitdiffhomepage
path: root/packages/api/src
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-02 21:57:06 +0900
committerAdam Malczewski <[email protected]>2026-06-02 21:57:06 +0900
commit4b45d33c256cf580a53054078be6fd7148fa6302 (patch)
tree0f549e08607f083d1f04306ce35e132923d6e3d3 /packages/api/src
parentd9f53727845dface3e6d8a84ba2270b1de55482b (diff)
downloaddispatch-4b45d33c256cf580a53054078be6fd7148fa6302.tar.gz
dispatch-4b45d33c256cf580a53054078be6fd7148fa6302.zip
Fix build scripts and deployment port issue
Diffstat (limited to 'packages/api/src')
-rw-r--r--packages/api/src/index.ts26
1 files changed, 13 insertions, 13 deletions
diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts
index 478abe0..5615e08 100644
--- a/packages/api/src/index.ts
+++ b/packages/api/src/index.ts
@@ -70,24 +70,24 @@ app.get(
export { app };
-// Starting port (overridable via PORT) and the inclusive ceiling we will bump
-// up to when a port is already in use. If 3000 is taken we try 3001, 3002, …
-// up to MAX_PORT, so multiple dispatch instances (e.g. testing several
-// features at once) can coexist without manually juggling ports. The frontend
-// defaults to :3000 — point it at the chosen port via the in-app API-URL
-// field / VITE_API_URL when a bump happens.
+// Starting port (overridable via PORT). When the port is already in use we
+// bump up one at a time (3000 → 3001 → 3002, …) until we find a free one, so
+// multiple dispatch instances (e.g. testing several features at once) can
+// coexist without manually juggling ports. The frontend defaults to :3000 —
+// point it at the chosen port via the in-app API-URL field / VITE_API_URL
+// when a bump happens.
const START_PORT = Number(process.env.PORT) || 3000;
-const MAX_PORT = 3010;
/**
* Bind the server to `START_PORT`, incrementing by one on EADDRINUSE until a
- * free port is found or MAX_PORT is exceeded. Bun's `Bun.serve` throws
- * synchronously when the port is taken, so we can catch and retry. Returns the
- * live server (whose `.port` reflects the port actually bound).
+ * free port is found (up to the maximum valid TCP port, 65535). Bun's
+ * `Bun.serve` throws synchronously when the port is taken, so we can catch and
+ * retry. Returns the live server (whose `.port` reflects the port actually
+ * bound).
*/
function serveWithPortFallback() {
let lastError: unknown;
- for (let port = START_PORT; port <= MAX_PORT; port++) {
+ for (let port = START_PORT; port <= 65535; port++) {
try {
const server = Bun.serve({
port,
@@ -113,10 +113,10 @@ function serveWithPortFallback() {
}
}
console.error(
- `dispatch: no free port in range ${START_PORT}-${MAX_PORT}. ` +
+ `dispatch: no free port at or above ${START_PORT}. ` +
`Free one up or set PORT to an open port.`,
);
- throw lastError ?? new Error(`No free port in range ${START_PORT}-${MAX_PORT}`);
+ throw lastError ?? new Error(`No free port at or above ${START_PORT}`);
}
// Only start the server when run as the entry point — importing this module