Skip to content

Latest commit

 

History

History
61 lines (42 loc) · 1.02 KB

README.md

File metadata and controls

61 lines (42 loc) · 1.02 KB

A simple plugin for Fastify list all available routes.

Installation

npm i fastify-list-routes
yarn add fastify-list-routes

Usage

Try to register a plugin as early as possible before register routes.

  • colors: If to use colors to highlight routes.

Example

const fastify = require("fastify")();
const fastifyListRoutes = require("fastify-list-routes");

async function run() {
  await fastify.register(fastifyListRoutes, { colors: true });

  fastify.get("/", (request, reply) => {
    reply.send({ hello: "world" });
  });

  fastify.get("/path1/:id", {
    async handler() {
      return { ok: true };
    },
  });

  fastify.post("/path2", {
    async handler() {
      return { ok: true };
    },
  });

  fastify.register(require("./demo"), { prefix: "/demo" });

  fastify.listen({ port: 3000 }, (err, address) => {
    if (err) throw err;

    console.log(`Server is now listening on ${address}`);
  });
}
run();

Result when started successfully

License

MIT