diff --git a/package.json b/package.json index 6daaca7..72d67ad 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/__tests__/__snapshots__/index.test.js.snap b/src/__tests__/__snapshots__/index.test.js.snap index 9b55a53..fe5e94c 100644 --- a/src/__tests__/__snapshots__/index.test.js.snap +++ b/src/__tests__/__snapshots__/index.test.js.snap @@ -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 " `; diff --git a/src/index.js b/src/index.js index b1352f9..11d3adb 100644 --- a/src/index.js +++ b/src/index.js @@ -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) {