This commit is contained in:
Benjamin Toby
2023-10-24 18:59:00 +01:00
parent d163438f7b
commit b9364a702c
68 changed files with 4701 additions and 4697 deletions
+135 -135
View File
@@ -1,135 +1,135 @@
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http");
const https = require("https");
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* ==============================================================================
* Main Function
* ==============================================================================
* @param {Object} mailObject - foundUser if any
*/
/** ********************* Main API Handler */
module.exports = async function httpFetch({ protocol, options, paradigm }) {
if (!protocol) protocol = "http";
/**
* Http(s) Response function
*
* @description handle http and https protocols differently
* @param {object} response => response object
* @param {Function} resolve => promise resolve method
* @param {Function} reject => promise reject method
*/
function httpResponse(response, resolve, reject) {
var str = "";
/** * Append data chunks to "str" variable
*/
response.on("data", function (chunk) {
str += chunk;
});
/** * the whole response has been received, so we just print it out here
*/
response.on("end", function () {
resolve(JSON.parse(str));
});
/** * Handle errors
*/
response.on("error", (err) => {
console.log(err);
reject("Fetch Failed");
});
}
/**
* Switch protocols
*
* @description handle http and https protocols differently
*/
switch (protocol) {
case "http":
/**
* Handle http protocol
*
* @description handles fetch requests with http protocol
* @see => handles strapi api calls only for now
*/
return await new Promise((resolve, reject) => {
http.request(
/** * Make Request
* @abstract Make Request
*/
{
...options,
host: "localhost",
port: "1337",
// path: "/api/blog-posts",
// href: "http://localhost:1337/api/blog-posts",
headers: {
Authorization: `bearer ${process.env.STRAPI_API_KEY_DEV}`,
},
},
/** * Handle Response
* @abstract Handle response
*/
(response) => {
httpResponse(response, resolve, reject);
}
).end();
});
break;
case "https":
/**
* Handle http protocol
*
* @description handles fetch requests with http protocol
* @see => handles strapi api calls only for now
*/
return await new Promise((resolve, reject) => {
https.request(
/** * Make Request
* @abstract Make Request
*/
{
...options,
host: "cms.showmerebates.com",
headers: {
Authorization: `bearer ${process.env.STRAPI_API_KEY}`,
},
},
/** * Handle Response
* @abstract Handle response
*/
(response) => {
httpResponse(response, resolve, reject);
}
).end();
});
break;
default:
break;
}
};
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http");
const https = require("https");
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* ==============================================================================
* Main Function
* ==============================================================================
* @param {Object} mailObject - foundUser if any
*/
/** ********************* Main API Handler */
module.exports = async function httpFetch({ protocol, options, paradigm }) {
if (!protocol) protocol = "http";
/**
* Http(s) Response function
*
* @description handle http and https protocols differently
* @param {object} response => response object
* @param {Function} resolve => promise resolve method
* @param {Function} reject => promise reject method
*/
function httpResponse(response, resolve, reject) {
var str = "";
/** * Append data chunks to "str" variable
*/
response.on("data", function (chunk) {
str += chunk;
});
/** * the whole response has been received, so we just print it out here
*/
response.on("end", function () {
resolve(JSON.parse(str));
});
/** * Handle errors
*/
response.on("error", (err) => {
console.log(err);
reject("Fetch Failed");
});
}
/**
* Switch protocols
*
* @description handle http and https protocols differently
*/
switch (protocol) {
case "http":
/**
* Handle http protocol
*
* @description handles fetch requests with http protocol
* @see => handles strapi api calls only for now
*/
return await new Promise((resolve, reject) => {
http.request(
/** * Make Request
* @abstract Make Request
*/
{
...options,
host: "localhost",
port: "1337",
// path: "/api/blog-posts",
// href: "http://localhost:1337/api/blog-posts",
headers: {
Authorization: `bearer ${process.env.STRAPI_API_KEY_DEV}`,
},
},
/** * Handle Response
* @abstract Handle response
*/
(response) => {
httpResponse(response, resolve, reject);
}
).end();
});
break;
case "https":
/**
* Handle http protocol
*
* @description handles fetch requests with http protocol
* @see => handles strapi api calls only for now
*/
return await new Promise((resolve, reject) => {
https.request(
/** * Make Request
* @abstract Make Request
*/
{
...options,
host: "cms.showmerebates.com",
headers: {
Authorization: `bearer ${process.env.STRAPI_API_KEY}`,
},
},
/** * Handle Response
* @abstract Handle response
*/
(response) => {
httpResponse(response, resolve, reject);
}
).end();
});
break;
default:
break;
}
};
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
+10 -10
View File
@@ -1,10 +1,10 @@
const sanitizeHtmlOptions: object = {
allowedTags: ["b", "i", "em", "strong", "a", "p", "span", "ul", "ol", "li", "h1", "h2", "h3", "h4", "h5", "h6", "img", "div", "button", "pre", "code", "br"],
allowedAttributes: {
a: ["href"],
img: ["src", "alt", "width", "height", "class", "style"],
"*": ["style", "class"],
},
};
export default sanitizeHtmlOptions;
const sanitizeHtmlOptions: object = {
allowedTags: ["b", "i", "em", "strong", "a", "p", "span", "ul", "ol", "li", "h1", "h2", "h3", "h4", "h5", "h6", "img", "div", "button", "pre", "code", "br"],
allowedAttributes: {
a: ["href"],
img: ["src", "alt", "width", "height", "class", "style"],
"*": ["style", "class"],
},
};
export default sanitizeHtmlOptions;