Skip to content

Commit

Permalink
better route highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelPolyakov committed Jan 19, 2018
1 parent fc1c96c commit 6ac1212
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 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.0.1",
"version": "1.0.2",
"description": "Print routes of your fastify instance",
"main": "src/index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`blipp / prints routes 1`] = `
"GET /hello/:username
GET /hello/:username/CAPS
POST /hello
"
`;
3 changes: 3 additions & 0 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}));
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6ac1212

Please sign in to comment.