UNPKG

@medflyt/test-db-service

Version:

Developer tool to instantly provision test PostgreSQL databases from a template

45 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.httpReq = void 0; const http = require("http"); async function httpReq(host, port, method, path, headers, reqBody) { const agent = new http.Agent({ keepAlive: false }); return await new Promise((resolve, reject) => { const timeout = setTimeout(() => { req.destroy(); const err = new Error("HTTP Timeout"); err.code = "ETIMEDOUT"; reject(err); }, 30000); const req = http.request({ agent: agent, host: host, hostname: host, port: port, method: method, path: path, headers: headers }, (response) => { let rawData = ""; response.on("data", chunk => { rawData += chunk; }); response.on("end", () => { const rsp = { statusCode: response.statusCode !== undefined ? response.statusCode : 0, headers: response.headers, body: rawData }; clearTimeout(timeout); resolve(rsp); }); }); req.on("error", (err) => { clearTimeout(timeout); reject(err); }); req.end(reqBody, "utf8"); }); } exports.httpReq = httpReq; //# sourceMappingURL=HttpClient.js.map