@bsv/overlay-express 0.1.0 → 0.1.1

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": "@bsv/overlay-express",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Overlay Express",
6
6
  "main": "dist/cjs/mod.js",
@@ -71,4 +71,4 @@
71
71
  "knex": "^3.1.0",
72
72
  "mongodb": "^6.11.0"
73
73
  }
74
- }
74
+ }
@@ -96,6 +96,9 @@ export default class OverlayExpress {
96
96
  // ARC API Key
97
97
  arcApiKey: string | undefined = undefined
98
98
 
99
+ // Verbose request logging
100
+ verboseRequestLogging: boolean = false
101
+
99
102
  /**
100
103
  * Constructs an instance of OverlayExpress.
101
104
  * @param name - The name of the service
@@ -166,6 +169,15 @@ export default class OverlayExpress {
166
169
  this.logger.log(`GASP synchronization ${enable ? 'enabled' : 'disabled'}.`)
167
170
  }
168
171
 
172
+ /**
173
+ * Enables or disables verbose request logging.
174
+ * @param enable - true to enable, false to disable
175
+ */
176
+ configureVerboseRequestLogging(enable: boolean) {
177
+ this.verboseRequestLogging = enable
178
+ this.logger.log(`Verbose request logging ${enable ? 'enabled' : 'disabled'}.`)
179
+ }
180
+
169
181
  /**
170
182
  * Configures the Knex (SQL) database connection.
171
183
  * @param config - Knex configuration object, or MySQL connection string (e.g. mysql://overlayAdmin:overlay123@mysql:3306/overlay).
@@ -328,6 +340,30 @@ export default class OverlayExpress {
328
340
  const engine = this.engine as Engine
329
341
  const knex = this.knex as Knex.Knex
330
342
 
343
+ if (this.verboseRequestLogging) {
344
+ this.app.use((req, res, next) => {
345
+ const startTime = Date.now();
346
+
347
+ // Log incoming request details
348
+ this.logger.log(`Incoming Request: ${req.method} ${req.originalUrl}`);
349
+ this.logger.log(`Headers: ${JSON.stringify(req.headers)}`);
350
+ if (req.body && Object.keys(req.body).length > 0) {
351
+ this.logger.log(`Request Body: ${JSON.stringify(req.body)}`);
352
+ }
353
+
354
+ // Log outgoing response details after the response is finished
355
+ res.on('finish', () => {
356
+ const duration = Date.now() - startTime;
357
+ this.logger.log(
358
+ `Outgoing Response: ${req.method} ${req.originalUrl} - Status: ${res.statusCode} - Duration: ${duration}ms`
359
+ );
360
+ this.logger.log(`Response Headers: ${JSON.stringify(res.getHeaders())}`);
361
+ });
362
+
363
+ next();
364
+ });
365
+ }
366
+
331
367
  this.app.use(bodyParser.json({ limit: '1gb', type: 'application/json' }))
332
368
  this.app.use(bodyParser.raw({ limit: '1gb', type: 'application/octet-stream' }))
333
369