tlsd 2.4.1 → 2.5.0

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.
package/inchtml.js ADDED
@@ -0,0 +1,40 @@
1
+
2
+ const fs = require( "fs" );
3
+
4
+ const { log, o2j, } = require( "sleepless" );
5
+
6
+
7
+ function parse( text ) {
8
+
9
+ const lines = text.split( /\n/g );
10
+
11
+ const newlines = [];
12
+
13
+ let ln = 0;
14
+ for( let line of lines ) {
15
+
16
+ ln += 1;
17
+
18
+ const words = line.split( /\s+/ );
19
+
20
+ if( words.shift() != "#include" ) {
21
+ newlines.push( line );
22
+ continue;
23
+ }
24
+
25
+ if( words.length < 1 ) {
26
+ throw new Error( "parse error on line "+ln );
27
+ }
28
+
29
+ const path = words.join( " " );
30
+
31
+ newlines.push( "**** included from file "+o2j(path) );
32
+
33
+ }
34
+
35
+ return newlines.join( "\n" );
36
+ }
37
+
38
+ let text = fs.readFileSync( process.argv[ 2 ], "utf8" );
39
+ log( parse( text ) );
40
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tlsd",
3
- "version": "2.4.1",
3
+ "version": "2.5.0",
4
4
  "description": "A server for web app prototyping with HTTPS and Websockets",
5
5
  "main": "tlsd.js",
6
6
  "bin": {
@@ -21,6 +21,7 @@
21
21
  "greenlock-express": "^4.0.3",
22
22
  "serve-static": "^1.15.0",
23
23
  "sleepless": "^5.7.0",
24
+ "tlsd": "^2.4.1",
24
25
  "websocket": "^1.0.34"
25
26
  }
26
27
  }
@@ -196,13 +196,10 @@
196
196
  let xhr = new XMLHttpRequest();
197
197
  xhr.onload = function() {
198
198
  let r = j2o( xhr.responseText );
199
- if( ! r ) {
199
+ if( r === null && xhr.responseText !== "null" ) {
200
200
  return fail( "Error parsing response from server." );
201
201
  }
202
- if( r.error ) {
203
- return fail( r.error );
204
- }
205
- okay( r.data, xhr );
202
+ okay( r, xhr );
206
203
  };
207
204
  xhr.onerror = fail;
208
205
  xhr.open( "POST", RPC_URL );
package/test.html ADDED
@@ -0,0 +1,4 @@
1
+ <html>
2
+ <head>
3
+ #include head.html
4
+ </head>
package/tlsd.js CHANGED
@@ -46,34 +46,34 @@ const next_seq = function() {
46
46
  // Tries to load the rpc handler module from root and if successful, passes the msg to it
47
47
  const rpc_handler = function( root, msg, _okay, _fail ) {
48
48
 
49
- D( "----------->>> RPC "+o2j( msg, null, 2 ));
49
+ D( "----------->>> RPC "+o2j( msg, null, 2 ) );
50
50
 
51
51
  const okay = data => {
52
- D( "<<<=========== RPC OKAY "+o2j(data, null, 2 ));
52
+ D( "<<<=========== RPC OKAY "+o2j( data, null, 2 ) );
53
53
  _okay( data );
54
54
  };
55
+
55
56
  const fail = error => {
56
- D( "<<<===******** RPC FAIL "+o2j(error, null, 2 ));
57
+ D( "<<<*********** RPC ERROR "+o2j( error, null, 2 ) );
57
58
  _fail( error );
58
59
  };
59
60
 
60
- const ouch = ( log_msg, error ) => {
61
- W( root + ": " + log_msg );
62
- if( error ) {
63
- E( error.stack );
64
- }
65
- fail( "RPC error" );
61
+ const ouch = audit_error => {
62
+ //E( root + ": " + audit_error );
63
+ fail( "RPC error" ); // this is returned to browser
66
64
  };
67
65
 
68
66
  try {
69
67
  const mod = require( root + "/rpc" );
70
68
  try {
71
- mod( msg, okay, fail );
69
+ mod( msg, okay, ouch );
72
70
  } catch( err ) {
73
- ouch( "RPC handler exception", err );
71
+ E( err );
72
+ ouch( "RPC handler exception" );
74
73
  }
75
74
  } catch( err ) {
76
- ouch( "Error loading RPC handler", err );
75
+ E( err );
76
+ ouch( "Error loading RPC handler" );
77
77
  }
78
78
  };
79
79
 
@@ -82,9 +82,9 @@ const rpc_handler = function( root, msg, _okay, _fail ) {
82
82
  // via the websockets msg object
83
83
  const ws_msg_handler = function( root, msg ) {
84
84
  rpc_handler( root, msg.msg, data => {
85
- msg.reply( { data } );
85
+ msg.reply( data );
86
86
  }, error => {
87
- msg.reply( { error } );
87
+ E( "This shouldn't happen." );
88
88
  } );
89
89
  };
90
90
 
package/foo/rpc/index.js DELETED
@@ -1,13 +0,0 @@
1
-
2
- module.exports = ( input, okay, fail ) => {
3
-
4
- const action = input.action;
5
-
6
- if( action == "hello" ) {
7
- return okay( "welcome" );
8
- }
9
-
10
- fail( "Invalid action: "+action );
11
-
12
- };
13
-
@@ -1,15 +0,0 @@
1
- <html>
2
- <body>
3
-
4
- <h1> Hello </h1>
5
-
6
- <script src="/rpc/rpc.js"></script>
7
-
8
- <script>
9
- RPC.on_connect = evt => {
10
- RPC( { action: "hello" }, console.log, alert );
11
- };
12
- </script>
13
-
14
- </body>
15
- </html>