aotrautils 0.0.598 → 0.0.600

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 (19/09/2023-23:43:39)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (23/09/2023-23:53:51)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -4997,7 +4997,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
4997
4997
 
4998
4998
 
4999
4999
 
5000
- /*utils CLIENT library associated with aotra version : «1_29072022-2359 (19/09/2023-23:43:39)»*/
5000
+ /*utils CLIENT library associated with aotra version : «1_29072022-2359 (23/09/2023-23:53:51)»*/
5001
5001
  /*-----------------------------------------------------------------------------*/
5002
5002
  /* ## Utility global methods in a browser (htmljs) client environment.
5003
5003
  *
@@ -6240,6 +6240,7 @@ function toConvention(type="snake",str){
6240
6240
  return result;
6241
6241
  }
6242
6242
 
6243
+ /*DEPRECATED, use new URL("...") instead !*/
6243
6244
  function getFileNameFromURL(url,/* OPTIONAL */forceHTMLFileNameAppending){
6244
6245
  var end=url.length;
6245
6246
  // From most outwards...
@@ -6258,6 +6259,7 @@ function getFileNameFromURL(url,/* OPTIONAL */forceHTMLFileNameAppending){
6258
6259
  return result;
6259
6260
  }
6260
6261
 
6262
+ /*DEPRECATED, use new URL("...") instead !*/
6261
6263
  function getCalculatedPageName(/* OPTIONAL */pathParam){
6262
6264
 
6263
6265
  var path=pathParam;
@@ -6294,6 +6296,7 @@ function getCalculatedPageName(/* OPTIONAL */pathParam){
6294
6296
  return getFileNameFromURL(path, true);
6295
6297
  }
6296
6298
 
6299
+ /*DEPRECATED, use new URL("...") instead !*/
6297
6300
  function getAbsoluteUrlForRelativeUrl(relativeURL){
6298
6301
  var serverURL=getCalculatedServerURLOnly();
6299
6302
  if (nothing(relativeURL))
@@ -6303,6 +6306,7 @@ function getAbsoluteUrlForRelativeUrl(relativeURL){
6303
6306
  return serverURL + relativeURL;
6304
6307
  }
6305
6308
 
6309
+ /*DEPRECATED, use new URL("...") instead !*/
6306
6310
  // Always has a final slash «/» appended on its end :
6307
6311
  function getCalculatedServerURLOnly(){
6308
6312
  var url=getWholeURLExceptQueryAndHash();
@@ -6310,6 +6314,7 @@ function getCalculatedServerURLOnly(){
6310
6314
  return addFinalSlashToURL(nothing(filename) ? url : url.replace("/" + filename, ""));
6311
6315
  }
6312
6316
 
6317
+ /*DEPRECATED, use new URL("...") instead !*/
6313
6318
  // CAUTION : TO USE THIS FUNCTION, YOU MUST BE SURE THAT THERE *IS* ACTUALLY A
6314
6319
  // SERVER PART, IT WILL NOT VERIFY BY ITSELF...
6315
6320
  // OR ELSE IT WILL CAUSE UNPREDICTABLE BEHAVIOR :
@@ -6324,6 +6329,17 @@ function removeServerPartOfURL(urlWithServerPart){
6324
6329
  return result.replace(result.substring(0, result.indexOf("/")), "").replace(/^\//gim, "");
6325
6330
  }
6326
6331
 
6332
+ /*DEPRECATED, use new URL("...") instead !*/
6333
+ /*UNUSED*/
6334
+ function getHostnameOfURL(url){
6335
+ const result=url;
6336
+ if (containsIgnoreCase(result, "(ht|f)tp[s]*://", true))
6337
+ result=result.replace(/(ht|f)tp[s]*:\/\//gim, "");
6338
+
6339
+ return result.substring(0, result.indexOf("/")).replace(/^\//gim, "");
6340
+ }
6341
+
6342
+ /*DEPRECATED, use new URL("...") instead !*/
6327
6343
  function getURLAnchor(){
6328
6344
  var url=document.location.href;
6329
6345
  if (!contains(url, "#"))
@@ -6331,6 +6347,7 @@ function getURLAnchor(){
6331
6347
  return url.substring(url.lastIndexOf("#") + 1, url.length);
6332
6348
  }
6333
6349
 
6350
+ /*DEPRECATED, use new URL("...") instead ! (see : https://developer.mozilla.org/en-US/docs/Web/API/URL)*/
6334
6351
  function getWholeURLExceptQueryAndHash(){
6335
6352
  return window.location.href.replace(window.location.search, "").replace(window.location.hash, "");
6336
6353
  }
@@ -13264,7 +13281,7 @@ createOritaMicroClient=function(url, port, isNode=false, staticMicroClientIdPara
13264
13281
 
13265
13282
 
13266
13283
 
13267
- /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (19/09/2023-23:43:39)»*/
13284
+ /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (23/09/2023-23:53:51)»*/
13268
13285
  /*-----------------------------------------------------------------------------*/
13269
13286
 
13270
13287
 
@@ -14503,7 +14520,7 @@ function rayVsUnitSphereClosestPoint(p, r) {
14503
14520
  // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
14504
14521
 
14505
14522
  AOTRAUTILS_GEOMETRY_LIB_IS_LOADED=true;
14506
- /*utils SERVER library associated with aotra version : «1_29072022-2359 (19/09/2023-23:43:39)»*/
14523
+ /*utils SERVER library associated with aotra version : «1_29072022-2359 (23/09/2023-23:53:51)»*/
14507
14524
  /*-----------------------------------------------------------------------------*/
14508
14525
 
14509
14526
 
@@ -15644,7 +15661,7 @@ WebsocketImplementation={
15644
15661
 
15645
15662
 
15646
15663
 
15647
- launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, /*OPTIONAL*/sslOptions=null){
15664
+ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, /*OPTIONAL*/sslOptions=null, httpHandlerParam=null){
15648
15665
 
15649
15666
  const EXCLUDED_FILENAMES_PARTS=[".keyHash."];
15650
15667
 
@@ -15662,7 +15679,7 @@ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, /
15662
15679
  }
15663
15680
 
15664
15681
 
15665
- const handler=function(request, response){
15682
+ const DEFAULT_HANDLER=function(request, response){
15666
15683
 
15667
15684
  const url=request.url;
15668
15685
 
@@ -15688,57 +15705,61 @@ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, /
15688
15705
  const urlFile="." + url;
15689
15706
 
15690
15707
  let filePath=urlFile.indexOf("?")!==-1?urlFile.split("?")[0]:urlFile;
15691
- if(filePath=="./") filePath="./index.html";
15692
-
15693
- let contentType="text/html";
15694
-
15695
- const headers={ "Content-Type": contentType };
15696
-
15697
- // 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)
15698
- if(ADD_CORS_HEADER) headers["Access-Control-Allow-Origin"]="*";
15699
-
15700
-
15701
- fs.readFile(filePath, function(error, fileContent){
15702
- if(error){
15703
- if(error.code=="ENOENT"){
15704
- // TRACE
15705
- console.log("ERROR 404 file not found :"+filePath);
15706
-
15707
- fs.readFile("./404.html", function(error, fileContent){
15708
- response.writeHead(200, headers);
15709
- response.end(fileContent, "utf-8");
15710
- });
15711
-
15712
- }else {
15713
-
15714
- // TRACE
15715
- console.log("ERROR 500 server error :");
15716
- console.log(error);
15717
-
15718
- response.writeHead(500);
15719
- response.end("Sorry, check with the site admin for error: "+error.code+" ..\n");
15720
- response.end();
15721
-
15722
- }
15723
- }else {
15724
-
15725
- // TRACE
15726
- console.log("INFO 200 OK :"+filePath);
15727
-
15728
-
15729
- response.writeHead(200, headers);
15730
- response.end(fileContent, "utf-8");
15731
-
15732
- // res.writeHead(200);
15733
- // res.end("hello world\n");
15734
- // res.sendFile(__dirname + "/public/index.html");
15735
-
15736
- }
15737
- });
15708
+ if(filePath=="./") filePath="./index.html";
15709
+
15710
+ let contentType="text/html";
15711
+
15712
+ const headers={ "Content-Type": contentType };
15713
+
15714
+ // 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)
15715
+ if(ADD_CORS_HEADER) headers["Access-Control-Allow-Origin"]="*";
15716
+
15717
+
15718
+ fs.readFile(filePath, function(error, fileContent){
15719
+ if(error){
15720
+ if(error.code=="ENOENT"){
15721
+ // TRACE
15722
+ console.log("ERROR 404 file not found :"+filePath);
15723
+
15724
+ fs.readFile("./404.html", function(error, fileContent){
15725
+ response.writeHead(200, headers);
15726
+ response.end(fileContent, "utf-8");
15727
+ });
15728
+
15729
+ }else {
15730
+
15731
+ // TRACE
15732
+ console.log("ERROR 500 server error :");
15733
+ console.log(error);
15734
+
15735
+ response.writeHead(500);
15736
+ response.end("Sorry, check with the site admin for error: "+error.code+" ..\n");
15737
+ response.end();
15738
+
15739
+ }
15740
+ }else {
15741
+
15742
+ // TRACE
15743
+ console.log("INFO 200 OK :"+filePath);
15744
+
15745
+
15746
+ response.writeHead(200, headers);
15747
+ response.end(fileContent, "utf-8");
15748
+
15749
+ // res.writeHead(200);
15750
+ // res.end("hello world\n");
15751
+ // res.sendFile(__dirname + "/public/index.html");
15752
+
15753
+ }
15754
+ });
15738
15755
 
15739
15756
  };
15740
15757
 
15741
15758
 
15759
+ const handler=nonull(httpHandlerParam, DEFAULT_HANDLER);
15760
+
15761
+
15762
+
15742
15763
  let listenableServer;
15743
15764
  if(sslOptions){
15744
15765
  let httpsServer=https.createServer(sslOptions, handler).listen(port);
aotrautils/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils",
3
- "version": "0.0.598",
3
+ "version": "0.0.600",
4
4
  "main": "aotrautils.build.js",
5
5
  "description": "A library for vanilla javascript utils (client-side) used in aotra javascript CMS",
6
6
  "author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",