Files
job/scrapper/src/main.ts
T
nikolaandClaude Opus 5.5 784c3c5220 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>
2026-10-12 21:43:34 +02:00

46 lines
1.9 KiB
TypeScript

// Entry point (also used by the compiled binary):
// 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] [--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}`);
process.exit(2);
}
const args = process.argv.slice(2);
let command: string | undefined;
for (let i = 0; i < args.length; i++) {
const arg = args[i]!;
if (arg === "--port" || arg === "-p" || arg.startsWith("--port=")) {
const value = arg.startsWith("--port=") ? arg.slice("--port=".length) : args[++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);
} else if (!command && !arg.startsWith("-")) {
command = arg;
} else {
fail(`Unknown argument "${arg}".`);
}
}
if (command === "scrape") {
const { runAllScrapers } = await import("./scrape");
const results = await runAllScrapers();
process.exit(results.some((r) => r.error) ? 1 : 0);
} else if (command === undefined || command === "serve") {
await import("./server");
} else {
fail(`Unknown command "${command}".`);
}