import { c as defineEventHandler, g as getQuery, e as createError } from '../../../_/nitro.mjs';
import { portToPid } from 'pid-port';
import fkill from 'fkill';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';

const killPort_post = defineEventHandler(async (event) => {
  var _a;
  const query = getQuery(event);
  const isPort = "port" in query;
  const signal = getQuery(event).signal;
  const processId = isPort ? (_a = await portToPid(Number(query.port))) != null ? _a : `:${query.port}` : query.process;
  return fkill(processId, { force: signal === "SIGKILL", tree: true }).catch((e) => {
    throw createError({
      statusCode: 400,
      message: e.message.split("\n")[1].trim()
    });
  });
});

export { killPort_post as default };
//# sourceMappingURL=kill-port.post.mjs.map
