Add --host flag, listen on 127.0.0.1 by default
The server previously bound to all interfaces with no auth. Default to loopback so it sits behind a reverse proxy; --host (or JOB_BOARD_HOST) overrides it. Plain HOST is ignored since some environments set it to the machine hostname. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
// Entry point (also used by the compiled binary):
|
||||
// job-board [serve] [--port <n>] start the web server (scrapes every 24h)
|
||||
// job-board scrape run all scrapers once and exit (exit code 1 if any failed)
|
||||
// job-board [serve] [--host <addr>] [--port <n>] start the web server (scrapes every 24h)
|
||||
// job-board scrape run all scrapers once and exit (exit code 1 if any failed)
|
||||
|
||||
export {};
|
||||
|
||||
const USAGE = "Usage: job-board [serve] [--port <n>] | job-board scrape";
|
||||
const USAGE = "Usage: job-board [serve] [--host <addr>] [--port <n>] | job-board scrape\n --host address to listen on (default 127.0.0.1; 0.0.0.0 = all interfaces)\n --port port to listen on (default 3000)";
|
||||
|
||||
function fail(message: string): never {
|
||||
console.error(`${message}\n${USAGE}`);
|
||||
@@ -20,6 +20,10 @@ for (let i = 0; i < args.length; i++) {
|
||||
const port = Number(value);
|
||||
if (!Number.isInteger(port) || port < 1 || port > 65535) fail(`Invalid port "${value ?? ""}".`);
|
||||
process.env.PORT = String(port); // read by server.ts; overrides the PORT env var
|
||||
} else if (arg === "--host" || arg.startsWith("--host=")) {
|
||||
const value = arg.startsWith("--host=") ? arg.slice("--host=".length) : args[++i];
|
||||
if (!value || value.startsWith("-")) fail(`Invalid host "${value ?? ""}".`);
|
||||
process.env.JOB_BOARD_HOST = value; // read by server.ts; overrides the env var
|
||||
} else if (arg === "--help" || arg === "-h") {
|
||||
console.log(USAGE);
|
||||
process.exit(0);
|
||||
|
||||
Reference in New Issue
Block a user