NO_AUTOPORT

This commit is contained in:
Chris Wanstrath 2026-01-28 10:52:00 -08:00
parent 1a8d422834
commit c054ca1f82
2 changed files with 3 additions and 0 deletions

View File

@ -13,6 +13,7 @@
`hype` wraps `hono` with useful features for fast prototyping: `hype` wraps `hono` with useful features for fast prototyping:
- HTTP logging to the console (disable with `NO_HTTP_LOG` env variable) - 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/` - Static files served from `pub/`
- Page-based routing to `.tsx` files that export a `JSX` function in `./src/pages` - 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` - Transpile `.ts` files in `src/client/blah.ts` via `website.com/client/blah.ts`

View File

@ -217,6 +217,8 @@ export class Hype<
// find an available port starting from the given port // find an available port starting from the given port
function findAvailablePort(startPort: number, maxAttempts = 100): number { function findAvailablePort(startPort: number, maxAttempts = 100): number {
if (process.env.NO_AUTOPORT) return startPort
for (let port = startPort; port < startPort + maxAttempts; port++) { for (let port = startPort; port < startPort + maxAttempts; port++) {
try { try {
const server = Bun.serve({ port, fetch: () => new Response() }) const server = Bun.serve({ port, fetch: () => new Response() })