Skip to content

Commit

Permalink
fix: restore 'debug' logs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dpopp07 committed Feb 18, 2025
1 parent 4f1b458 commit 3e10034
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==================

* Restore `debug` dependency

2.1.0 / 2025-02-10
==================

Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Layer = require('./lib/layer')
const { METHODS } = require('node:http')
const parseUrl = require('parseurl')
const Route = require('./lib/route')
const debug = require('debug')('router')

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

debug('dispatching %s %s', req.method, req.url)

let idx = 0
let methods
const protohost = getProtohost(req.url) || ''
Expand Down Expand Up @@ -315,6 +318,7 @@ Router.prototype.handle = function handle (req, res, callback) {

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

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

debug('%s %s : %s', layer.name, layerPath, req.originalUrl)

if (layerError) {
layer.handleError(layerError, req, res, next)
} else {
Expand Down Expand Up @@ -387,6 +393,8 @@ Router.prototype.use = function use (handler) {
}

// add the middleware
debug('use %o %s', path, fn.name || '<anonymous>')

const layer = new Layer(path, {
sensitive: this.caseSensitive,
strict: false,
Expand Down
2 changes: 2 additions & 0 deletions lib/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

const isPromise = require('is-promise')
const pathRegexp = require('path-to-regexp')
const debug = require('debug')('router:layer')

/**
* Module variables.
Expand All @@ -34,6 +35,7 @@ function Layer (path, options, fn) {
return new Layer(path, options, fn)
}

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

this.handle = fn
Expand Down
4 changes: 4 additions & 0 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @private
*/

const debug = require('debug')('router:route')
const Layer = require('./layer')
const { METHODS } = require('node:http')

Expand Down Expand Up @@ -43,6 +44,7 @@ module.exports = Route
*/

function Route (path) {
debug('new %o', path)
this.path = path
this.stack = []

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

debug('%s %s', method, this.path)

const layer = Layer('/', {}, fn)
layer.method = method

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"license": "MIT",
"repository": "pillarjs/router",
"dependencies": {
"debug": "^4.4.0",
"is-promise": "^4.0.0",
"parseurl": "^1.3.3",
"path-to-regexp": "^8.0.0"
Expand Down

0 comments on commit 3e10034

Please sign in to comment.