From c054ca1f82a4aa8338ce55ef57bf093bc219a64c Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Wed, 28 Jan 2026 10:52:00 -0800 Subject: [PATCH] NO_AUTOPORT --- README.md | 1 + src/index.tsx | 2 ++ 2 files changed, 3 insertions(+) diff --git a/README.md b/README.md index f5d3221..7aebe61 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ `hype` wraps `hono` with useful features for fast prototyping: - HTTP logging to the console (disable with `NO_HTTP_LOG` env variable) +- Auto-port selection in dev mode: if the port is busy, tries the next one (disable with `NO_AUTOPORT` env variable) - Static files served from `pub/` - Page-based routing to `.tsx` files that export a `JSX` function in `./src/pages` - Transpile `.ts` files in `src/client/blah.ts` via `website.com/client/blah.ts` diff --git a/src/index.tsx b/src/index.tsx index f5c5947..9f242c3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -217,6 +217,8 @@ export class Hype< // find an available port starting from the given port function findAvailablePort(startPort: number, maxAttempts = 100): number { + if (process.env.NO_AUTOPORT) return startPort + for (let port = startPort; port < startPort + maxAttempts; port++) { try { const server = Bun.serve({ port, fetch: () => new Response() })