29 lines
814 B
TypeScript
29 lines
814 B
TypeScript
import { startHttpServer } from "../../http/server.js";
|
|
import { numberOption, stringOption } from "../parser.js";
|
|
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
|
|
|
export async function handleHttpCommand(
|
|
parsed: CliParsedArgs,
|
|
runtime: CliRuntime
|
|
): Promise<CliResult> {
|
|
const port = numberOption(parsed.options, ["port", "p"]);
|
|
const host = stringOption(parsed.options, ["host", "h"]);
|
|
|
|
const server = await startHttpServer({ port, host, silent: runtime.jsonMode });
|
|
|
|
// Handle graceful shutdown
|
|
const shutdown = () => {
|
|
server.close(() => {
|
|
process.exit(0);
|
|
});
|
|
};
|
|
|
|
process.on("SIGINT", shutdown);
|
|
process.on("SIGTERM", shutdown);
|
|
|
|
// Keep alive in foreground
|
|
await new Promise<void>(() => {});
|
|
|
|
return { stdout: "", stderr: "", exitCode: 0 };
|
|
}
|