24 lines
679 B
TypeScript
24 lines
679 B
TypeScript
import { numberOption, stringOption } from "../parser.js";
|
|
import type { ParsedArgs } from "../types.js";
|
|
import { startHttpServer } from "../../http/server.js";
|
|
|
|
export async function handleHttpCommand(args: ParsedArgs) {
|
|
const port = numberOption(args.options.port) ?? numberOption(args.options.p);
|
|
const host = stringOption(args.options.host) ?? stringOption(args.options.h);
|
|
|
|
const server = await startHttpServer({ port, host });
|
|
|
|
// Handle graceful shutdown
|
|
const shutdown = () => {
|
|
server.close(() => {
|
|
process.exit(0);
|
|
});
|
|
};
|
|
|
|
process.on("SIGINT", shutdown);
|
|
process.on("SIGTERM", shutdown);
|
|
|
|
// Keep alive
|
|
await new Promise(() => {});
|
|
}
|