From 30c73c5e013dd58a3bbc1de20ee0559289f7b0b6 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 26 Jul 2025 12:40:08 +1000 Subject: [PATCH] Read number of workers and port from environment vars --- deno_server.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/deno_server.ts b/deno_server.ts index d1907a9..1679c23 100644 --- a/deno_server.ts +++ b/deno_server.ts @@ -8,7 +8,9 @@ const States = Object.freeze({ // Create a pool of workers. const workerPool: { worker: Worker; inUse: boolean }[] = []; -const numWorkers = navigator.hardwareConcurrency; +// Allow the number of workers to be configured via an environment variable. +const numWorkers = + parseInt(Deno.env.get("NUM_WORKERS") || "0") || navigator.hardwareConcurrency; for (let i = 0; i < numWorkers; i++) { const worker = new Worker(new URL("./worker.ts", import.meta.url).href, { @@ -92,6 +94,8 @@ async function handler(req: Request): Promise { } } -console.log(`⚡ Deno server ready on :8000 with ${numWorkers} workers.`); +const port = parseInt(Deno.env.get("PORT") || "8000"); -await serve(handler, { port: 8000 }); +console.log(`⚡ Deno server ready on :${port} with ${numWorkers} workers.`); + +await serve(handler, { port });