diff --git a/package.json b/package.json index a6bf3ea..1ae8651 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fastify-blipp", - "version": "1.0.1", + "version": "1.0.2", "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 d2c70d1..c4f7406 100644 --- a/src/__tests__/__snapshots__/index.test.js.snap +++ b/src/__tests__/__snapshots__/index.test.js.snap @@ -2,6 +2,7 @@ exports[`blipp / prints routes 1`] = ` "GET /hello/:username +GET /hello/:username/CAPS POST /hello " `; diff --git a/src/__tests__/index.test.js b/src/__tests__/index.test.js index f0298a1..37ee59d 100644 --- a/src/__tests__/index.test.js +++ b/src/__tests__/index.test.js @@ -19,6 +19,9 @@ describe("blipp", () => { fastify.get("/hello/:username", async (req, reply) => ({ greeting: `Hello, ${req.params.username}` })); + fastify.get("/hello/:username/CAPS", async (req, reply) => ({ + greeting: `Hello, ${req.params.username.toUpperCase()}` + })); fastify.post("/hello", async (req, reply) => ({ greeting: `Hello, ${req.body.username}` })); diff --git a/src/index.js b/src/index.js index ac22b79..13379db 100644 --- a/src/index.js +++ b/src/index.js @@ -8,8 +8,8 @@ module.exports = fp(function(fastify, opts, next) { for (let url in route) { Object.keys(route[url]).forEach(method => { routes += `${chalk.green(method.toUpperCase())}\t${url.replace( - /(:.*?(\/|$))/g, - chalk.gray("$1") + /(?:\:[\w]+|\[\:\w+\])/g, + chalk.gray("$&") )}\n`; }); } diff --git a/var/examples/two-routes-server.js b/var/examples/four-kind-of-routes-server.js similarity index 65% rename from var/examples/two-routes-server.js rename to var/examples/four-kind-of-routes-server.js index e6b1baf..658d5a4 100644 --- a/var/examples/two-routes-server.js +++ b/var/examples/four-kind-of-routes-server.js @@ -5,9 +5,19 @@ fastify.register(require("../../src/index")); fastify.get("/hello/:username", async (req, reply) => ({ greeting: `Hello, ${req.params.username}` })); +fastify.get("/hello/:username/CAPS", async (req, reply) => ({ + greeting: `Hello, ${req.params.username.toUpperCase()}` +})); fastify.post("/hello", async (req, reply) => ({ greeting: `Hello, ${req.body.username}` })); +fastify.get( + "/example/at/:hour(^\\\\d{2})h:minute(^\\\\d{2})m", + (req, reply) => ({ + hour: req.params.hour, + minute: req.params.minute + }) +); const start = async () => { try {