daveappserver 0.6.10 → 0.6.12

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.
Files changed (2) hide show
  1. package/appserver.js +31 -19
  2. package/package.json +2 -1
package/appserver.js CHANGED
@@ -1,4 +1,4 @@
1
- var myVersion = "0.6.10", myProductName = "daveAppServer";
1
+ var myVersion = "0.6.12", myProductName = "daveAppServer";
2
2
 
3
3
  exports.start = startup;
4
4
  exports.notifySocketSubscribers = notifySocketSubscribers;
@@ -23,6 +23,7 @@ const folderToJson = require ("foldertojson");
23
23
  const zip = require ("davezip");
24
24
  const qs = require ("querystring");
25
25
  const mail = require ("davemail");
26
+ const requireFromString = require ("require-from-string"); //2/10/23 by DW
26
27
 
27
28
  const whenStart = new Date ();
28
29
 
@@ -60,6 +61,8 @@ var config = {
60
61
  dataFolder: "data/",
61
62
  confirmationExpiresAfter: 60 * 60, //emails expire after an hour
62
63
 
64
+ flSecureWebsocket: false, //2/8/23 by DW
65
+
63
66
  isUserInDatabase: function (screenname, callback) { //2/6/23 by DW
64
67
  callback (false);
65
68
  },
@@ -172,7 +175,7 @@ function checkPathForIllegalChars (path) {
172
175
  return (false);
173
176
  }
174
177
  switch (ch) {
175
- case "/": case "_": case "-": case ".": case " ": case "*":
178
+ case "/": case "_": case "-": case ".": case " ": case "*": case "@":
176
179
  return (false);
177
180
  }
178
181
  return (true);
@@ -245,6 +248,10 @@ function cleanFileStats (stats) { //4/19/21 by DW
245
248
  //sockets
246
249
  var theWsServer = undefined;
247
250
 
251
+ function getWsProtocol () { //2/8/23 by DW
252
+ const protocol = (utils.getBoolean (config.flSecureWebsocket)) ? "wss://" : "ws://";
253
+ return (protocol);
254
+ }
248
255
  function notifySocketSubscribers (verb, payload, flPayloadIsString, callbackToQualify) {
249
256
  if (theWsServer !== undefined) {
250
257
  var ctUpdates = 0, now = new Date (), ctTotalSockets = 0;
@@ -337,6 +344,7 @@ function cleanFileStats (stats) { //4/19/21 by DW
337
344
 
338
345
  conn.on ("text", function (s) {
339
346
  var words = s.split (" ");
347
+ console.log ("handleWebSocketConnection: s == " + s); //6/7/21 by DW
340
348
  if (words.length > 1) { //new protocol as of 11/29/15 by DW
341
349
  conn.appData.whenLastUpdate = now;
342
350
  conn.appData.lastVerb = words [0];
@@ -1077,24 +1085,26 @@ function startup (options, callback) {
1077
1085
  });
1078
1086
  }
1079
1087
  function readConfigJson (callback) { //2/8/23 by DW
1080
- var configJs;
1081
- try {
1082
- configJs = require ("./config.js");
1083
- }
1084
- catch (err) { //try in the parent directory, assuming daveappserver is running in lib sub-directory
1085
- try {
1086
- configJs = require ("../config.js");
1088
+ fs.readFile ("config.js", function (err, scripttext) {
1089
+ var flReadConfigJson = true;
1090
+ if (!err) {
1091
+ try {
1092
+ scripttext = scripttext.toString ();
1093
+ var jstruct = requireFromString (scripttext);
1094
+ for (var x in jstruct) {
1095
+ config [x] = jstruct [x];
1096
+ }
1097
+ flReadConfigJson = false;
1098
+ callback ();
1099
+ }
1100
+ catch (err) {
1101
+ console.log (err.message);
1102
+ }
1087
1103
  }
1088
- catch (err) { //fallback to reading config.json
1104
+ if (flReadConfigJson) {
1089
1105
  readConfig (fnameConfig, config, true, callback);
1090
- return;
1091
1106
  }
1092
- }
1093
- const jstruct = configJs;
1094
- for (var x in jstruct) {
1095
- config [x] = jstruct [x];
1096
- }
1097
- callback ();
1107
+ });
1098
1108
  }
1099
1109
  function startDavetwitter (httpRequestCallback) { //patch over a design problem in starting up davetwitter and davehttp -- 7/20/20 by DW
1100
1110
  if (config.twitter === undefined) {
@@ -1226,7 +1236,8 @@ function startup (options, callback) {
1226
1236
  prefsPath: config.prefsPath,
1227
1237
  docsPath: config.docsPath,
1228
1238
  flUseTwitterIdentity: config.flUseTwitterIdentity, //2/6/23 by DW
1229
- idGitHubClient: config.githubClientId //11/9/21 by DW
1239
+ idGitHubClient: config.githubClientId, //11/9/21 by DW
1240
+ flWebsocketEnabled: config.flWebsocketEnabled //2/8/23 by DW
1230
1241
  };
1231
1242
  if (theRequest.addToPagetable !== undefined) { //3/9/21 by DW
1232
1243
  for (var x in theRequest.addToPagetable) {
@@ -1558,6 +1569,7 @@ function startup (options, callback) {
1558
1569
  }
1559
1570
  }
1560
1571
 
1572
+
1561
1573
  utils.copyScalars (options, config); //1/22/21 by DW
1562
1574
  readConfigJson (function () { //readConfig (fnameConfig, config, true, function () { //anything can be overridden by config.json
1563
1575
  readConfig (fnameStats, stats, false, function () {
@@ -1580,7 +1592,7 @@ function startup (options, callback) {
1580
1592
  config.urlServerForClient = "http://" + config.myDomain + "/";
1581
1593
  }
1582
1594
  if (config.urlWebsocketServerForClient === undefined) { //1/30/23 by DW
1583
- config.urlWebsocketServerForClient = "ws://" + utils.stringNthField (config.myDomain, ":", 1) + ":" + config.websocketPort + "/";
1595
+ config.urlWebsocketServerForClient = getWsProtocol () + utils.stringNthField (config.myDomain, ":", 1) + ":" + config.websocketPort + "/";
1584
1596
  }
1585
1597
  webSocketStartup ();
1586
1598
  setInterval (everySecond, 1000);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "daveappserver",
3
3
  "description": "Factored code that was appearing in all my servers.",
4
- "version": "0.6.10",
4
+ "version": "0.6.12",
5
5
  "main": "appserver.js",
6
6
  "repository": {
7
7
  "type" : "git",
@@ -15,6 +15,7 @@
15
15
  "querystring": "*",
16
16
  "request": "*",
17
17
  "nodejs-websocket": "*",
18
+ "require-from-string": "*",
18
19
  "daveutils": "*",
19
20
  "davefilesystem": "*",
20
21
  "foldertojson": "*",