aotrautils-srv 0.0.776 → 0.0.777
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
/*utils COMMONS library associated with aotra version : «1_29072022-2359 (
|
|
3
|
+
/*utils COMMONS library associated with aotra version : «1_29072022-2359 (13/02/2024-23:56:32)»*/
|
|
4
4
|
/*-----------------------------------------------------------------------------*/
|
|
5
5
|
|
|
6
6
|
|
|
@@ -5167,7 +5167,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
|
|
|
5167
5167
|
|
|
5168
5168
|
|
|
5169
5169
|
|
|
5170
|
-
/*utils SERVER library associated with aotra version : «1_29072022-2359 (
|
|
5170
|
+
/*utils SERVER library associated with aotra version : «1_29072022-2359 (13/02/2024-23:56:32)»*/
|
|
5171
5171
|
/*-----------------------------------------------------------------------------*/
|
|
5172
5172
|
|
|
5173
5173
|
|
|
@@ -6843,7 +6843,71 @@ getListManager=function(config){
|
|
|
6843
6843
|
}
|
|
6844
6844
|
|
|
6845
6845
|
|
|
6846
|
+
function performHTTPRequestNode(url,httpMethod="GET",headers={},postRequestBodyOrNamedArgs=null){
|
|
6847
|
+
|
|
6848
|
+
|
|
6849
|
+
if(!require){
|
|
6850
|
+
// TODO : FIXME : Support also a browser context!!
|
|
6851
|
+
lognow("ERROR : 'require()' not found, this may need we are not running in a nodejs context. This is currently not supported. Aborting");
|
|
6852
|
+
throw new Error("Unsupported context non-nodejs for performHTTPRequestNode().");
|
|
6853
|
+
}
|
|
6854
|
+
|
|
6855
|
+
const isSecure=completeURL.includes("https://");
|
|
6856
|
+
const httpHandler = isSecure?require("https"):require("http");
|
|
6857
|
+
|
|
6858
|
+
// Options for the HTTP request
|
|
6859
|
+
const options = {
|
|
6860
|
+
url: completeURL,
|
|
6861
|
+
method: httpMethod,
|
|
6862
|
+
};
|
|
6863
|
+
|
|
6864
|
+
if(contains(["POST","PUT"],httpMethod)){
|
|
6865
|
+
options.json=true;
|
|
6866
|
+
headers["Content-Type"]="application/json";
|
|
6867
|
+
// To remove the CORS error message (cf. https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9)
|
|
6868
|
+
if(ADD_CORS_HEADER) headers["Access-Control-Allow-Origin"]="*";
|
|
6869
|
+
}
|
|
6870
|
+
|
|
6871
|
+
options.headers=headers;
|
|
6872
|
+
|
|
6873
|
+
return new Promise((accept,resolve)=>{
|
|
6874
|
+
|
|
6875
|
+
// Create the HTTP request
|
|
6876
|
+
const request = httpHandler.request(options, (response) => {
|
|
6877
|
+
|
|
6878
|
+
let responseData = "";
|
|
6846
6879
|
|
|
6880
|
+
// A chunk of data has been received.
|
|
6881
|
+
response.on('data', (chunk) => {
|
|
6882
|
+
responseData += chunk;
|
|
6883
|
+
});
|
|
6884
|
+
|
|
6885
|
+
// The whole response has been received.
|
|
6886
|
+
response.on('end', () => {
|
|
6887
|
+
resolve(responseData);
|
|
6888
|
+
});
|
|
6889
|
+
});
|
|
6890
|
+
|
|
6891
|
+
// Handle errors
|
|
6892
|
+
request.on('error', (error) => {
|
|
6893
|
+
reject(error);
|
|
6894
|
+
});
|
|
6895
|
+
|
|
6896
|
+
|
|
6897
|
+
// Not the same way to send parameters in POST http method :
|
|
6898
|
+
if(contains(["POST","PUT"],httpMethod)){
|
|
6899
|
+
// (We need to stringify parameters or else we'll have an error :)
|
|
6900
|
+
if(!empty(postRequestBodyOrNamedArgs)){
|
|
6901
|
+
request.write(stringifyObject(postRequestBodyOrNamedArgs));
|
|
6902
|
+
}
|
|
6903
|
+
}
|
|
6904
|
+
|
|
6905
|
+
// End the request
|
|
6906
|
+
request.end();
|
|
6907
|
+
|
|
6908
|
+
});
|
|
6909
|
+
|
|
6910
|
+
}
|
|
6847
6911
|
|
|
6848
6912
|
|
|
6849
6913
|
|
aotrautils-srv/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aotrautils-srv",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.777",
|
|
4
4
|
"main": "aotrautils-srv.build.js",
|
|
5
5
|
"description": "A library for vanilla javascript utils (server-side) used in aotra javascript CMS",
|
|
6
6
|
"author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",
|