
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@rhinolabs/fastify-file-routes
Advanced tools
A Next.js-style file-based routing plugin for Fastify. This plugin is the core routing engine behind the @rhinolabs/boilr
framework but can be used independently with any Fastify application.
[param]
syntax[...param]
syntax(group)
prefix for folders to organize without affecting URLsget
, post
, put
, patch
, del
schema
object for validation with any schema systemnpm install @rhinolabs/fastify-file-routes
# or
yarn add @rhinolabs/fastify-file-routes
# or
pnpm add @rhinolabs/fastify-file-routes
import fastify from 'fastify';
import { fastifyFileRoutes } from '@rhinolabs/fastify-file-routes';
const app = fastify();
app.register(fastifyFileRoutes, {
routesDir: './routes', // Required: directory containing route files
prefix: '/api', // Optional: prefix for all routes
});
app.listen({ port: 3000 });
routes/
├── index.js # GET /
├── users/
│ ├── index.js # GET/POST /users
│ └── [id].js # GET/PUT/PATCH/DELETE /users/:id
├── posts/
│ ├── index.js # GET/POST /posts
│ └── [...slug].js # GET/POST/etc. /posts/*
└── (admin)/ # Route grouping (doesn't affect URL)
└── settings.js # GET /settings
Create route handlers by exporting named functions matching the HTTP methods:
// routes/users/[id].js
import { z } from 'zod';
// Schema definition (optional)
export const schema = {
get: {
params: z.object({
id: z.string(),
}),
response: {
200: z.object({
id: z.string(),
name: z.string(),
}),
},
},
};
// GET handler
export async function get(request, reply) {
const { id } = request.params;
return { id, name: `User ${id}` };
}
// POST handler
export async function post(request, reply) {
const { id } = request.params;
return reply.status(201).send({ id, created: true });
}
// PUT handler
export async function put(request, reply) {
const { id } = request.params;
return { id, updated: true };
}
// PATCH handler
export async function patch(request, reply) {
const { id } = request.params;
return { id, patched: true };
}
// DELETE handler (using 'del' not 'delete')
export async function del(request, reply) {
const { id } = request.params;
return { id, deleted: true };
}
File Path | HTTP Method | Route Path |
---|---|---|
routes/index.js | GET | / |
routes/users/index.js | GET | /users |
routes/users/[id].js | GET | /users/:id |
routes/posts/[...slug].js | GET | /posts/* |
routes/(admin)/settings.js | GET | /settings |
// routes/users/[id].js
export async function get(request, reply) {
const { id } = request.params;
return { id };
}
// routes/docs/[...path].js
export async function get(request, reply) {
const { path } = request.params; // Will be an array of segments
return { path };
}
// routes/[[...slug]].js - matches / or any path
export async function get(request, reply) {
const { slug = [] } = request.params; // Will be undefined or an array
return { slug };
}
app.register(fastifyFileRoutes, {
routesDir: './routes',
prefix: '/api',
options: {
// File patterns to ignore
ignore: [/\.test\.js$/, /\.spec\.js$/],
// File extensions to include (defaults to .js, .cjs, .mjs, .ts)
extensions: ['.js', '.ts'],
// Custom path transformation function
pathTransform: (path, filename) => {
return path.toLowerCase();
}
}
});
Works seamlessly with Fastify's schema validation:
// With Zod (requires fastify-zod or similar)
import { z } from 'zod';
export const schema = {
get: {
params: z.object({
id: z.string()
}),
response: {
200: z.object({
id: z.string(),
name: z.string()
})
}
}
};
MIT
FAQs
Next.js-style file-based routing for Fastify
The npm package @rhinolabs/fastify-file-routes receives a total of 0 weekly downloads. As such, @rhinolabs/fastify-file-routes popularity was classified as not popular.
We found that @rhinolabs/fastify-file-routes demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.