Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
fastify-autoroute
Advanced tools
Readme
Next.js file routing for Fastify.
If you're familiar with Next.js, you know how awesome the routing is. If not, have a look on their documentation :)
AutoRoute gives you exactly the same routing (except for optional catch all routes, they can't be done in Fastify or they're inherently supported, je sais pas 🤷♀️).
yarn add fastify-autoroute
# or
npm i fastify-autoroute
Add AutoRoute as a plugin to Fastify:
import { FastifyPlugin } from "fastify";
import { join } from "path";
import fastifyAutoRoute from "fastify-autoroute";
const app: FastifyPlugin = function (fastify, opts, next): void {
fastify.register(fastifyAutoRoute, {
autoRouteDir: join(__dirname, "routes"),
});
next();
};
export default app;
/pages
.I tried explaining this, but instead here is an example
For the following directory:
├───routes
│ ├───users
│ │ ├───[id]
│ │ │ ├───index.get.ts
│ │ │ ├───index.delete.ts
│ │ │ ├───name.get.ts
│ │ │ └───email.get.ts
│ │ └───index.post.ts
│ ├───teams
│ │ ├───[...slug].get.ts
│ └───index.get.ts
You will get the following Fastify routes:
GET /
POST /users
GET /users/name
GET /users/email
GET /users/:id
DELETE /users/:id
GET /teams/*
Note. the method all
is expanded into all the methods supported by Fastify.
So, name.all.ts
is expanded into
GET /name
POST /name
PUT /name
...
The default export is passed as a handler
to fastify.route()
. All other named exports are bassed as options to fastify.route()
too.
export const schema = {};
export const onRequest = [];
export default async (request: FastifyRequest, reply: FastifyReply) => {
return { ok: true };
};
In order to access Fastify and its decorators, you can use the following structure:
export default (fastify: FastifyInstance) => async (
request: FastifyRequest,
reply: FastifyReply
) => {
return {
config: fastify.config,
};
};
The same structure applies when accessing Fastify from inside onRequest
:
export const onRequest = [
(fastify) => async (request, reply) => {
// your content
return;
},
];
Currently, accessing Fastify from inside other hooks is not supported.
Imed Adel (Twitter)
MIT
FAQs
> Next.js file routing for Fastify.
The npm package fastify-autoroute receives a total of 5 weekly downloads. As such, fastify-autoroute popularity was classified as not popular.
We found that fastify-autoroute demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.