daveappserver 0.6.10 → 0.6.11

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 +29 -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.11", 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,24 @@ 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
+ var jstruct = requireFromString (scripttext);
1093
+ for (var x in configJs) {
1094
+ config [x] = jstruct [x];
1095
+ }
1096
+ flReadConfigJson = false;
1097
+ callback ();
1098
+ }
1099
+ catch (err) {
1100
+ }
1087
1101
  }
1088
- catch (err) { //fallback to reading config.json
1102
+ if (flReadConfigJson) {
1089
1103
  readConfig (fnameConfig, config, true, callback);
1090
- return;
1091
1104
  }
1092
- }
1093
- const jstruct = configJs;
1094
- for (var x in jstruct) {
1095
- config [x] = jstruct [x];
1096
- }
1097
- callback ();
1105
+ });
1098
1106
  }
1099
1107
  function startDavetwitter (httpRequestCallback) { //patch over a design problem in starting up davetwitter and davehttp -- 7/20/20 by DW
1100
1108
  if (config.twitter === undefined) {
@@ -1226,7 +1234,8 @@ function startup (options, callback) {
1226
1234
  prefsPath: config.prefsPath,
1227
1235
  docsPath: config.docsPath,
1228
1236
  flUseTwitterIdentity: config.flUseTwitterIdentity, //2/6/23 by DW
1229
- idGitHubClient: config.githubClientId //11/9/21 by DW
1237
+ idGitHubClient: config.githubClientId, //11/9/21 by DW
1238
+ flWebsocketEnabled: config.flWebsocketEnabled //2/8/23 by DW
1230
1239
  };
1231
1240
  if (theRequest.addToPagetable !== undefined) { //3/9/21 by DW
1232
1241
  for (var x in theRequest.addToPagetable) {
@@ -1558,6 +1567,7 @@ function startup (options, callback) {
1558
1567
  }
1559
1568
  }
1560
1569
 
1570
+
1561
1571
  utils.copyScalars (options, config); //1/22/21 by DW
1562
1572
  readConfigJson (function () { //readConfig (fnameConfig, config, true, function () { //anything can be overridden by config.json
1563
1573
  readConfig (fnameStats, stats, false, function () {
@@ -1580,7 +1590,7 @@ function startup (options, callback) {
1580
1590
  config.urlServerForClient = "http://" + config.myDomain + "/";
1581
1591
  }
1582
1592
  if (config.urlWebsocketServerForClient === undefined) { //1/30/23 by DW
1583
- config.urlWebsocketServerForClient = "ws://" + utils.stringNthField (config.myDomain, ":", 1) + ":" + config.websocketPort + "/";
1593
+ config.urlWebsocketServerForClient = getWsProtocol () + utils.stringNthField (config.myDomain, ":", 1) + ":" + config.websocketPort + "/";
1584
1594
  }
1585
1595
  webSocketStartup ();
1586
1596
  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.11",
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": "*",