@j0nnyboi/amman
Version:
A modern mandatory toolbelt to help test solana SDK libraries and apps on a locally running validator.
52 lines • 1.76 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidHttpUrl = exports.resolveServerAddress = exports.killRunningServer = void 0;
// @ts-ignore (no declaration file)
const port_pid_1 = __importDefault(require("port-pid"));
const utils_1 = require("../utils");
/** private */
async function killRunningServer(port) {
var _a;
const loggedInfoFor = new Set();
while (true) {
const pids = (_a = (await (0, port_pid_1.default)(port)).tcp) !== null && _a !== void 0 ? _a : [];
if (pids.length === 0)
break;
const pid = pids[0];
if (!loggedInfoFor.has(pid)) {
(0, utils_1.logInfo)(`Killing app (${pid}) currently running amman relay at port ${port}`);
loggedInfoFor.add(pid);
}
try {
process.kill(pid, 'SIGTERM');
(0, utils_1.logDebug)(`Sent 'SIGTERM' to ${pid}`);
await (0, utils_1.sleep)(2000);
}
catch (err) {
(0, utils_1.logError)(err);
}
}
}
exports.killRunningServer = killRunningServer;
function resolveServerAddress(server) {
const address = server.address();
return typeof address === 'string'
? address
: `${address.address}:${address.port}`;
}
exports.resolveServerAddress = resolveServerAddress;
function isValidHttpUrl(maybeUrl) {
let url;
try {
url = new URL(maybeUrl);
}
catch (_) {
return false;
}
return url.protocol === 'http:' || url.protocol === 'https:';
}
exports.isValidHttpUrl = isValidHttpUrl;
//# sourceMappingURL=http.js.map