Skip to content

Commit

Permalink
Merge 19fd1f2 into 7e6996e
Browse files Browse the repository at this point in the history
  • Loading branch information
jadach1 committed Feb 27, 2019
2 parents 7e6996e + 19fd1f2 commit 5335ade
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/letsRoute.js
Expand Up @@ -29,6 +29,10 @@ Anumargak.prototype._onEvent = function (eventName, fn) {
this.eventEmitter.on(_name, fn);
}

// Object used to hold list of routes we can print for debugging
var listOfRoutes = [];
var listOfMethods = {};

/**
* Adds routes against the given method and URL
* @param {string | array} method
Expand Down Expand Up @@ -66,6 +70,14 @@ Anumargak.prototype.on = function (method, url, options, fn, extraData) {
throw Error("Invalid method argument. String or array is expected.");
}

// Save the list method, url and version to be printed
listOfMethods[method] = {};
listOfRoutes.push({
method: method,
url: url,
version: options.version ? options.version : ""
})

return this;
}

Expand Down Expand Up @@ -598,4 +610,52 @@ function defaultRoute(req, res) {
res.statusCode = 404
res.end()
}

Anumargak.prototype.printRoutes = function(){

process.stdout.write("\nLIST OF Methods Used\n"+
"--------------------\n\n");

console.log( Object.keys(listOfMethods))

process.stdout.write("\nLIST OF STATIC AND DYNAMIC ROUTES\n"+
"---------------------------------\n\n");

// variable which we will print to the screen
var stringToPrint;

// Iterate through each of the methods
Object.keys(listOfMethods).forEach(function(key, index){

process.stdout.write(key + "\n { \n");

// Iterate through all of the objects which hold the route url's and versions
for(var i=0; i < listOfRoutes.length; i++){

// reset the string we use to print to the screen
stringToPrint = "";

// We will print this object if its method matches the listOfMethods object
if ( key == listOfRoutes [ i ] . method)
{
// start constructing the string which will be printed out
stringToPrint = " " + listOfRoutes [ i ] .url;

// check to see if there is a version and if there is append it to the string
if ( listOfRoutes [i] .version)
{
stringToPrint += " { with version => " + listOfRoutes [i] .version + " }\n";
} else {
// no version, append a newline to the string
stringToPrint += "\n"
}
// print out route to screen
process.stdout.write(stringToPrint);
}
}
// newlines for the next method
process.stdout.write(" }\n\n");
});
}

module.exports = Anumargak;

0 comments on commit 5335ade

Please sign in to comment.