Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/PavelPolyakov/fastify-blipp
https://github.com/PavelPolyakov/fastify-blipp
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/PavelPolyakov/fastify-blipp
- Owner: PavelPolyakov
- Created: 2018-01-19T14:27:55.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-14T12:37:49.000Z (almost 2 years ago)
- Last Synced: 2024-11-15T22:34:43.999Z (2 months ago)
- Language: JavaScript
- Size: 1.11 MB
- Stars: 31
- Watchers: 3
- Forks: 5
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-fastify - `fastify-blipp`
README
`fastify-blipp` prints your routes to the console. So each time your server starts, you know which endpoints are available.
(inspired by [blipp](https://github.com/danielb2/blipp) hapijs plugin)
## install
```
npm i fastify-blipp
```## usage
It is important to register the plugin as soon as possible, so it starts to listen for the new routes.```javascript
import { fastify as fastifyInstance} from "fastify";
import blippPlugin from "fastify-blipp";const fastify = fastifyInstance();
// register it as early as possible
fastify.register(blippPlugin);
//or if you wan't custom log function
// fastify.register(require("fastify-blipp"), {blippLog: (msg) => console.log(msg)});fastify.register(
(fastify, {}, done) => {
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",
async (req, reply) => ({
hour: req.params.hour,
minute: req.params.minute
})
);
done();
}
)const start = async () => {
try {
await fastify.listen({port:3000});fastify.blipp();
console.log(`server listening on ${fastify.server.address().port}`);
} catch (err) {
console.error(err);
process.exit(1);
}
};start();
```## result
![image](var/images/output_example.png)