Skip to content

Commit

Permalink
better echo for the complex routes;
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelPolyakov committed Jun 26, 2018
1 parent 9b1e651 commit 0adc1c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fastify-blipp",
"version": "1.2.0",
"version": "1.2.1",
"description": "Print routes of your fastify instance",
"main": "src/index.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`blipp / prints routes 1`] = `
"POST /hello
GET /hello/:username
GET /hello/:username/CAPS
[\\"GET\\",\\"HEAD\\"] /hello/complex-route
GET /hello/complex-route
HEAD /hello/complex-route
"
`;
17 changes: 14 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,20 @@ module.exports = fp(function(fastify, opts, next) {

let output = "";
for (let route of routes) {
output += `${chalk.green(
!Array.isArray(route.method) ? route.method.toUpperCase() : JSON.stringify(route.method.map(s => s.toUpperCase()))
)}\t${route.url.replace(/(?:\:[\w]+|\[\:\w+\])/g, chalk.gray("$&"))}\n`;
let methods = [];
// one route can support more than one method
if (!Array.isArray(route.method)) {
methods.push(route.method);
} else {
methods = route.method.sort((a, b) => a > b);
}

methods.forEach(method => {
output += `${chalk.green(method.toUpperCase())}\t${route.url.replace(
/(?:\:[\w]+|\[\:\w+\])/g,
chalk.gray("$&")
)}\n`;
});
}

if (routes.length > 0) {
Expand Down

0 comments on commit 0adc1c2

Please sign in to comment.