mirror of
https://github.com/joelwmale/webhook-action.git
synced 2026-09-05 18:14:43 +08:00
v2.1.0
This commit is contained in:
+25
-13
@@ -1,35 +1,47 @@
|
||||
const fetch = require('node-fetch');
|
||||
var https = require('https');
|
||||
const fetch = require('node-fetch')
|
||||
var https = require('https')
|
||||
|
||||
class Http {
|
||||
make(url: string, headers: string | null, body: string | null, ignoreCertificate: boolean | null): Promise<any> {
|
||||
make(
|
||||
url: string,
|
||||
headers: string | null,
|
||||
body: string | null,
|
||||
ignoreCertificate: boolean | null
|
||||
): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(url, this.getOptions('post', headers, body, ignoreCertificate))
|
||||
.then((res: Response) => resolve(res));
|
||||
});
|
||||
fetch(
|
||||
url,
|
||||
this.getOptions('post', headers, body, ignoreCertificate)
|
||||
).then((res: Response) => resolve(res))
|
||||
})
|
||||
}
|
||||
|
||||
getOptions(method: string, headers: string | null, body: string | null, ignoreCertificate: boolean | null) {
|
||||
getOptions(
|
||||
method: string,
|
||||
headers: string | null,
|
||||
body: string | null,
|
||||
ignoreCertificate: boolean | null
|
||||
) {
|
||||
const options: any = {
|
||||
headers: headers ? JSON.parse(headers) : {},
|
||||
method
|
||||
};
|
||||
}
|
||||
|
||||
if (body) {
|
||||
// parse the body
|
||||
options.body = body;
|
||||
options.body = body
|
||||
}
|
||||
|
||||
if (ignoreCertificate) {
|
||||
// ignore the certificate by not rejecting authorized servers
|
||||
options.agent = new https.Agent({ rejectUnauthorized: false });
|
||||
options.agent = new https.Agent({rejectUnauthorized: false})
|
||||
}
|
||||
|
||||
// set these headers
|
||||
options.headers['content-type'] = 'application/json';
|
||||
options.headers['content-type'] = 'application/json'
|
||||
|
||||
return options;
|
||||
return options
|
||||
}
|
||||
}
|
||||
|
||||
export const http = new Http();
|
||||
export const http = new Http()
|
||||
|
||||
Reference in New Issue
Block a user