webhook/dist/http.js

32 lines
1.1 KiB
JavaScript
Raw Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.http = void 0;
var fetch = require('node-fetch');
2021-02-26 05:00:44 +01:00
var https = require('https');
var Http = (function () {
function Http() {
}
2021-02-26 05:00:44 +01:00
Http.prototype.make = function (url, headers, body, ignoreCertificate) {
var _this = this;
return new Promise(function (resolve, reject) {
2021-02-26 05:00:44 +01:00
fetch(url, _this.getOptions('post', headers, body, ignoreCertificate)).then(function (res) { return resolve(res); });
});
};
2021-02-26 05:00:44 +01:00
Http.prototype.getOptions = function (method, headers, body, ignoreCertificate) {
var options = {
2020-08-26 02:41:58 +02:00
headers: headers ? JSON.parse(headers) : {},
method: method
};
2020-08-26 02:41:58 +02:00
if (body) {
options.body = body;
}
2021-02-26 05:00:44 +01:00
if (ignoreCertificate) {
options.agent = new https.Agent({ rejectUnauthorized: false });
}
options.headers['content-type'] = 'application/json';
return options;
};
return Http;
}());
exports.http = new Http();
//# sourceMappingURL=http.js.map