aotrautils-srv 0.0.593 → 0.0.595

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-00:15:48)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (22/09/2023-01:28:20)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -4997,7 +4997,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
4997
4997
 
4998
4998
 
4999
4999
 
5000
- /*utils SERVER library associated with aotra version : «1_29072022-2359 (19/09/2023-00:15:48)»*/
5000
+ /*utils SERVER library associated with aotra version : «1_29072022-2359 (22/09/2023-01:28:20)»*/
5001
5001
  /*-----------------------------------------------------------------------------*/
5002
5002
 
5003
5003
 
@@ -6138,7 +6138,7 @@ WebsocketImplementation={
6138
6138
 
6139
6139
 
6140
6140
 
6141
- launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, /*OPTIONAL*/sslOptions=null){
6141
+ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, /*OPTIONAL*/sslOptions=null, httpHandlerParam=null){
6142
6142
 
6143
6143
  const EXCLUDED_FILENAMES_PARTS=[".keyHash."];
6144
6144
 
@@ -6156,7 +6156,7 @@ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, /
6156
6156
  }
6157
6157
 
6158
6158
 
6159
- const handler=function(request, response){
6159
+ const DEFAULT_HANDLER=function(request, response){
6160
6160
 
6161
6161
  const url=request.url;
6162
6162
 
@@ -6182,57 +6182,61 @@ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, /
6182
6182
  const urlFile="." + url;
6183
6183
 
6184
6184
  let filePath=urlFile.indexOf("?")!==-1?urlFile.split("?")[0]:urlFile;
6185
- if(filePath=="./") filePath="./index.html";
6186
-
6187
- let contentType="text/html";
6188
-
6189
- const headers={ "Content-Type": contentType };
6190
-
6191
- // 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)
6192
- if(ADD_CORS_HEADER) headers["Access-Control-Allow-Origin"]="*";
6193
-
6194
-
6195
- fs.readFile(filePath, function(error, fileContent){
6196
- if(error){
6197
- if(error.code=="ENOENT"){
6198
- // TRACE
6199
- console.log("ERROR 404 file not found :"+filePath);
6200
-
6201
- fs.readFile("./404.html", function(error, fileContent){
6202
- response.writeHead(200, headers);
6203
- response.end(fileContent, "utf-8");
6204
- });
6205
-
6206
- }else {
6207
-
6208
- // TRACE
6209
- console.log("ERROR 500 server error :");
6210
- console.log(error);
6211
-
6212
- response.writeHead(500);
6213
- response.end("Sorry, check with the site admin for error: "+error.code+" ..\n");
6214
- response.end();
6215
-
6216
- }
6217
- }else {
6218
-
6219
- // TRACE
6220
- console.log("INFO 200 OK :"+filePath);
6221
-
6222
-
6223
- response.writeHead(200, headers);
6224
- response.end(fileContent, "utf-8");
6225
-
6226
- // res.writeHead(200);
6227
- // res.end("hello world\n");
6228
- // res.sendFile(__dirname + "/public/index.html");
6229
-
6230
- }
6231
- });
6185
+ if(filePath=="./") filePath="./index.html";
6186
+
6187
+ let contentType="text/html";
6188
+
6189
+ const headers={ "Content-Type": contentType };
6190
+
6191
+ // 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)
6192
+ if(ADD_CORS_HEADER) headers["Access-Control-Allow-Origin"]="*";
6193
+
6194
+
6195
+ fs.readFile(filePath, function(error, fileContent){
6196
+ if(error){
6197
+ if(error.code=="ENOENT"){
6198
+ // TRACE
6199
+ console.log("ERROR 404 file not found :"+filePath);
6200
+
6201
+ fs.readFile("./404.html", function(error, fileContent){
6202
+ response.writeHead(200, headers);
6203
+ response.end(fileContent, "utf-8");
6204
+ });
6205
+
6206
+ }else {
6207
+
6208
+ // TRACE
6209
+ console.log("ERROR 500 server error :");
6210
+ console.log(error);
6211
+
6212
+ response.writeHead(500);
6213
+ response.end("Sorry, check with the site admin for error: "+error.code+" ..\n");
6214
+ response.end();
6215
+
6216
+ }
6217
+ }else {
6218
+
6219
+ // TRACE
6220
+ console.log("INFO 200 OK :"+filePath);
6221
+
6222
+
6223
+ response.writeHead(200, headers);
6224
+ response.end(fileContent, "utf-8");
6225
+
6226
+ // res.writeHead(200);
6227
+ // res.end("hello world\n");
6228
+ // res.sendFile(__dirname + "/public/index.html");
6229
+
6230
+ }
6231
+ });
6232
6232
 
6233
6233
  };
6234
6234
 
6235
6235
 
6236
+ const handler=nonull(httpHandlerParam, DEFAULT_HANDLER);
6237
+
6238
+
6239
+
6236
6240
  let listenableServer;
6237
6241
  if(sslOptions){
6238
6242
  let httpsServer=https.createServer(sslOptions, handler).listen(port);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.593",
3
+ "version": "0.0.595",
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)",