tlsd 2.12.0 → 2.12.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tlsd",
3
- "version": "2.12.0",
3
+ "version": "2.12.2",
4
4
  "description": "A server for web app prototyping with HTTPS and Websockets",
5
5
  "main": "tlsd.js",
6
6
  "bin": {
package/tlsd.js CHANGED
@@ -44,10 +44,10 @@ function next_seq() {
44
44
 
45
45
  // Handles incoming RPC msgs.
46
46
  // Tries to load the rpc handler module from root and if successful, passes the msg to it
47
- // xport:
48
- // { type: "WS", transport: { ... } }
49
- // { type: "GET", transport: { req, res } }
50
- // { type: "POST", transport: { req, res } }
47
+ // transport =
48
+ // { type: "WS", connection: { ... } }
49
+ // { type: "GET", connection: { req, res } }
50
+ // { type: "POST", connection: { req, res } }
51
51
  function rpc_handler( root, msg, transport, _okay, _fail ) {
52
52
 
53
53
  let ll = toInt( msg.log_level );
@@ -82,16 +82,36 @@ function rpc_handler( root, msg, transport, _okay, _fail ) {
82
82
  };
83
83
 
84
84
  try {
85
- const mod = require( root + "/rpc" );
85
+ // try loading explicit common js module
86
+ const path = root + "/rpc/index.cjs";
87
+ V( "path=" + path );
88
+ const mod = require( path );
86
89
  try {
87
90
  mod( msg, okay, ouch, transport );
88
91
  } catch( err ) {
89
- E( (err instanceof Error ) ? err.stack : err );
90
- ouch( "RPC handler exception" );
92
+ E( (err instanceof Error ) ? err.stack : err );
93
+ ouch( "RPC handler exception" );
91
94
  }
95
+
92
96
  } catch( err ) {
93
- E( (err instanceof Error ) ? err.stack : err );
94
- ouch( "Error loading RPC handler" );
97
+
98
+ // try loading it the old way using the dir
99
+ try {
100
+ const path = root + "/rpc";
101
+ V( "path=" + path );
102
+ const mod = require( path );
103
+ try {
104
+ mod( msg, okay, ouch, transport );
105
+ } catch( err ) {
106
+ E( (err instanceof Error ) ? err.stack : err );
107
+ ouch( "RPC handler exception" );
108
+ }
109
+
110
+ } catch( err ) {
111
+ E( (err instanceof Error ) ? err.stack : err );
112
+ ouch( "Error loading RPC handler" );
113
+ }
114
+
95
115
  }
96
116
  };
97
117
 
@@ -99,7 +119,7 @@ function rpc_handler( root, msg, transport, _okay, _fail ) {
99
119
  // Glue function to call rpc handler module and then return response
100
120
  // via the websockets msg object
101
121
  function ws_msg_handler( root, msg, connection ) {
102
- rpc_handler( root, msg.msg, { type: "WS", transport: connection }, data => {
122
+ rpc_handler( root, msg.msg, { type: "WS", connection }, data => {
103
123
  msg.reply( data );
104
124
  }, error => {
105
125
  msg.error( { error } );
@@ -165,7 +185,7 @@ function rpc_post( root ) {
165
185
  const fail = ( error, body ) => { done( error, body ); };
166
186
 
167
187
  // Summon the rpc handler for the domain root.
168
- rpc_handler( root, input, { type, method, transport: { req, res, } } , okay, fail );
188
+ rpc_handler( root, input, { type: method, connection: { req, res, } } , okay, fail );
169
189
  };
170
190
  }
171
191
 
@@ -274,7 +294,7 @@ function ws_attach( server, msg_handler ) {
274
294
  const name = "ws-conn-"+next_seq(); // XXX just use the websocket id
275
295
 
276
296
  // send msg to connected client
277
- const send = function( msg , cb ) {
297
+ const send = function( msg, cb ) {
278
298
  if( msg.msg_id === undefined ) {
279
299
  msg.msg_id = "msg-id-" + next_seq(); // every message must have an id
280
300
  }
@@ -396,8 +416,8 @@ if( argv.length == 5 ) {
396
416
  rest_handler( SITE_ROOT, req, res );
397
417
  } );
398
418
 
399
- ws_attach( server, ( msg, conn, domain ) => {
400
- ws_msg_handler( SITE_ROOT, msg );
419
+ ws_attach( server, ( msg, connection, domain ) => {
420
+ ws_msg_handler( SITE_ROOT, msg, connection );
401
421
  } );
402
422
 
403
423
  server.listen( toInt( PORT ), () => {
File without changes