Skip to content

Commit 3e10034

Browse files
author
Dustin Popp
committed
fix: restore 'debug' logs
Revert "Remove debug dependency", with the following changes: - Update "var" to "const" for debug imports - Preserve history file so intermediate versions are documented correctly - Use latest version of debug This reverts commit 0b5a0a6.
1 parent 4f1b458 commit 3e10034

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased
2+
==================
3+
4+
* Restore `debug` dependency
5+
16
2.1.0 / 2025-02-10
27
==================
38

index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const Layer = require('./lib/layer')
1717
const { METHODS } = require('node:http')
1818
const parseUrl = require('parseurl')
1919
const Route = require('./lib/route')
20+
const debug = require('debug')('router')
2021

2122
/**
2223
* Module variables.
@@ -149,6 +150,8 @@ Router.prototype.handle = function handle (req, res, callback) {
149150
throw new TypeError('argument callback is required')
150151
}
151152

153+
debug('dispatching %s %s', req.method, req.url)
154+
152155
let idx = 0
153156
let methods
154157
const protohost = getProtohost(req.url) || ''
@@ -315,6 +318,7 @@ Router.prototype.handle = function handle (req, res, callback) {
315318

316319
// Trim off the part of the url that matches the route
317320
// middleware (.use stuff) needs to have the path stripped
321+
debug('trim prefix (%s) from url %s', layerPath, req.url)
318322
removed = layerPath
319323
req.url = protohost + req.url.slice(protohost.length + removed.length)
320324

@@ -330,6 +334,8 @@ Router.prototype.handle = function handle (req, res, callback) {
330334
: removed)
331335
}
332336

337+
debug('%s %s : %s', layer.name, layerPath, req.originalUrl)
338+
333339
if (layerError) {
334340
layer.handleError(layerError, req, res, next)
335341
} else {
@@ -387,6 +393,8 @@ Router.prototype.use = function use (handler) {
387393
}
388394

389395
// add the middleware
396+
debug('use %o %s', path, fn.name || '<anonymous>')
397+
390398
const layer = new Layer(path, {
391399
sensitive: this.caseSensitive,
392400
strict: false,

lib/layer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
const isPromise = require('is-promise')
1616
const pathRegexp = require('path-to-regexp')
17+
const debug = require('debug')('router:layer')
1718

1819
/**
1920
* Module variables.
@@ -34,6 +35,7 @@ function Layer (path, options, fn) {
3435
return new Layer(path, options, fn)
3536
}
3637

38+
debug('new %o', path)
3739
const opts = options || {}
3840

3941
this.handle = fn

lib/route.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @private
1313
*/
1414

15+
const debug = require('debug')('router:route')
1516
const Layer = require('./layer')
1617
const { METHODS } = require('node:http')
1718

@@ -43,6 +44,7 @@ module.exports = Route
4344
*/
4445

4546
function Route (path) {
47+
debug('new %o', path)
4648
this.path = path
4749
this.stack = []
4850

@@ -231,6 +233,8 @@ methods.forEach(function (method) {
231233
throw new TypeError('argument handler must be a function')
232234
}
233235

236+
debug('%s %s', method, this.path)
237+
234238
const layer = Layer('/', {}, fn)
235239
layer.method = method
236240

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"license": "MIT",
1010
"repository": "pillarjs/router",
1111
"dependencies": {
12+
"debug": "^4.4.0",
1213
"is-promise": "^4.0.0",
1314
"parseurl": "^1.3.3",
1415
"path-to-regexp": "^8.0.0"

0 commit comments

Comments
 (0)