Skip to content

Instantly share code, notes, and snippets.

@ErisDS
Last active April 24, 2020 15:12
Show Gist options
  • Save ErisDS/2fec0b64f28a945cb8d4 to your computer and use it in GitHub Desktop.
Save ErisDS/2fec0b64f28a945cb8d4 to your computer and use it in GitHub Desktop.

Revisions

  1. ErisDS revised this gist May 28, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion stackPrinter.js
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ module.exports = function stackPrinter(req, res, next) {
    } else if (item.name === '<anonymous>') {
    console.log(prefix, item.name, item.handle);
    } else {
    console.log(prefix, item.name);
    console.log(prefix, item.name, item.method ? '(' + item.method.toUpperCase() + ')' : '');
    }

    printSubItems(item, prefix + ' -');
  2. ErisDS created this gist May 28, 2015.
    45 changes: 45 additions & 0 deletions stackPrinter.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    module.exports = function stackPrinter(req, res, next) {
    console.log('Printing Stack For', req.url);

    function printItem(item, prefix) {
    prefix = prefix || '';

    if (item.route) {
    console.log(prefix, 'Route', item.route.path);
    } else if (item.name === '<anonymous>') {
    console.log(prefix, item.name, item.handle);
    } else {
    console.log(prefix, item.name);
    }

    printSubItems(item, prefix + ' -');
    }

    function printSubItems(item, prefix) {
    if (item.name === 'router') {
    console.log(prefix, 'MATCH', item.regexp);

    if (item.handle.stack) {
    item.handle.stack.forEach(function (subItem) {
    printItem(subItem, prefix);
    });
    }
    }

    if (item.route && item.route.stack) {
    item.route.stack.forEach(function (subItem) {
    printItem(subItem, prefix);
    });
    }

    if (item.name === 'mounted_app') {
    console.log(prefix, 'MATCH', item.regexp);
    }
    }

    req.app._router.stack.forEach(function(stackItem) {
    printItem(stackItem);
    });

    next();
    });